@itwin/presentation-core-interop 2.0.0-alpha.2 → 2.0.0-alpha.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/README.md +17 -7
  3. package/lib/core-interop/Formatting.d.ts +74 -0
  4. package/lib/core-interop/Formatting.d.ts.map +1 -0
  5. package/lib/core-interop/Formatting.js +95 -0
  6. package/lib/core-interop/Formatting.js.map +1 -0
  7. package/lib/core-interop/IModelKey.d.ts.map +1 -0
  8. package/lib/core-interop/IModelKey.js.map +1 -0
  9. package/lib/core-interop/Logging.d.ts.map +1 -0
  10. package/lib/core-interop/Logging.js.map +1 -0
  11. package/lib/core-interop/Metadata.d.ts +76 -0
  12. package/lib/core-interop/Metadata.d.ts.map +1 -0
  13. package/lib/core-interop/Metadata.js +508 -0
  14. package/lib/core-interop/Metadata.js.map +1 -0
  15. package/lib/{cjs/core-interop → core-interop}/QueryExecutor.d.ts +1 -2
  16. package/lib/core-interop/QueryExecutor.d.ts.map +1 -0
  17. package/lib/core-interop/QueryExecutor.js.map +1 -0
  18. package/lib/core-interop/Transactions.d.ts.map +1 -0
  19. package/lib/core-interop/Transactions.js.map +1 -0
  20. package/lib/presentation-core-interop.d.ts.map +1 -0
  21. package/lib/presentation-core-interop.js.map +1 -0
  22. package/package.json +24 -26
  23. package/lib/cjs/core-interop/Formatting.d.ts +0 -45
  24. package/lib/cjs/core-interop/Formatting.d.ts.map +0 -1
  25. package/lib/cjs/core-interop/Formatting.js +0 -136
  26. package/lib/cjs/core-interop/Formatting.js.map +0 -1
  27. package/lib/cjs/core-interop/IModelKey.d.ts.map +0 -1
  28. package/lib/cjs/core-interop/IModelKey.js +0 -36
  29. package/lib/cjs/core-interop/IModelKey.js.map +0 -1
  30. package/lib/cjs/core-interop/Logging.d.ts.map +0 -1
  31. package/lib/cjs/core-interop/Logging.js +0 -46
  32. package/lib/cjs/core-interop/Logging.js.map +0 -1
  33. package/lib/cjs/core-interop/Metadata.d.ts +0 -30
  34. package/lib/cjs/core-interop/Metadata.d.ts.map +0 -1
  35. package/lib/cjs/core-interop/Metadata.js +0 -62
  36. package/lib/cjs/core-interop/Metadata.js.map +0 -1
  37. package/lib/cjs/core-interop/MetadataInternal.d.ts +0 -10
  38. package/lib/cjs/core-interop/MetadataInternal.d.ts.map +0 -1
  39. package/lib/cjs/core-interop/MetadataInternal.js +0 -427
  40. package/lib/cjs/core-interop/MetadataInternal.js.map +0 -1
  41. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +0 -1
  42. package/lib/cjs/core-interop/QueryExecutor.js +0 -150
  43. package/lib/cjs/core-interop/QueryExecutor.js.map +0 -1
  44. package/lib/cjs/core-interop/Transactions.d.ts.map +0 -1
  45. package/lib/cjs/core-interop/Transactions.js +0 -60
  46. package/lib/cjs/core-interop/Transactions.js.map +0 -1
  47. package/lib/cjs/package.json +0 -1
  48. package/lib/cjs/presentation-core-interop.d.ts.map +0 -1
  49. package/lib/cjs/presentation-core-interop.js +0 -20
  50. package/lib/cjs/presentation-core-interop.js.map +0 -1
  51. package/lib/esm/core-interop/Formatting.d.ts +0 -45
  52. package/lib/esm/core-interop/Formatting.d.ts.map +0 -1
  53. package/lib/esm/core-interop/Formatting.js +0 -133
  54. package/lib/esm/core-interop/Formatting.js.map +0 -1
  55. package/lib/esm/core-interop/IModelKey.d.ts +0 -31
  56. package/lib/esm/core-interop/IModelKey.d.ts.map +0 -1
  57. package/lib/esm/core-interop/IModelKey.js.map +0 -1
  58. package/lib/esm/core-interop/Logging.d.ts +0 -33
  59. package/lib/esm/core-interop/Logging.d.ts.map +0 -1
  60. package/lib/esm/core-interop/Logging.js.map +0 -1
  61. package/lib/esm/core-interop/Metadata.d.ts +0 -30
  62. package/lib/esm/core-interop/Metadata.d.ts.map +0 -1
  63. package/lib/esm/core-interop/Metadata.js +0 -59
  64. package/lib/esm/core-interop/Metadata.js.map +0 -1
  65. package/lib/esm/core-interop/MetadataInternal.d.ts +0 -10
  66. package/lib/esm/core-interop/MetadataInternal.d.ts.map +0 -1
  67. package/lib/esm/core-interop/MetadataInternal.js +0 -422
  68. package/lib/esm/core-interop/MetadataInternal.js.map +0 -1
  69. package/lib/esm/core-interop/QueryExecutor.d.ts +0 -34
  70. package/lib/esm/core-interop/QueryExecutor.d.ts.map +0 -1
  71. package/lib/esm/core-interop/QueryExecutor.js.map +0 -1
  72. package/lib/esm/core-interop/Transactions.d.ts +0 -71
  73. package/lib/esm/core-interop/Transactions.d.ts.map +0 -1
  74. package/lib/esm/core-interop/Transactions.js.map +0 -1
  75. package/lib/esm/presentation-core-interop.d.ts +0 -7
  76. package/lib/esm/presentation-core-interop.d.ts.map +0 -1
  77. package/lib/esm/presentation-core-interop.js.map +0 -1
  78. /package/lib/{cjs/core-interop → core-interop}/IModelKey.d.ts +0 -0
  79. /package/lib/{esm/core-interop → core-interop}/IModelKey.js +0 -0
  80. /package/lib/{cjs/core-interop → core-interop}/Logging.d.ts +0 -0
  81. /package/lib/{esm/core-interop → core-interop}/Logging.js +0 -0
  82. /package/lib/{esm/core-interop → core-interop}/QueryExecutor.js +0 -0
  83. /package/lib/{cjs/core-interop → core-interop}/Transactions.d.ts +0 -0
  84. /package/lib/{esm/core-interop → core-interop}/Transactions.js +0 -0
  85. /package/lib/{cjs/presentation-core-interop.d.ts → presentation-core-interop.d.ts} +0 -0
  86. /package/lib/{esm/presentation-core-interop.js → presentation-core-interop.js} +0 -0
@@ -1,60 +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
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.registerTxnListeners = registerTxnListeners;
8
- /**
9
- * Registers listeners to `txns` events and calls provided `onChanged` callback when transaction manager
10
- * reports there are iModel data changes.
11
- *
12
- * Usage example:
13
- *
14
- * ```ts
15
- * import { BriefcaseDb } from "@itwin/core-backend";
16
- * import { registerTxnListeners } from "@itwin/presentation-core-interop";
17
- * import { HierarchyProvider } from "@itwin/presentation-hierarchies";
18
- *
19
- * // get iModel and hierarchy provider from arbitrary sources
20
- * const db: BriefcaseDb = getIModel();
21
- * const provider: HierarchyProvider = getHierarchyProvider();
22
- *
23
- * // register the listeners
24
- * const unregister = registerTxnListeners(db.txns, () => {
25
- * // notify provided about the changed data
26
- * provider.notifyDataSourceChanged();
27
- * // TODO: force the components using `provider` to reload
28
- * });
29
- *
30
- * // clean up on iModel close
31
- * db.onClosed.addOnce(() => unregister());
32
- * ```
33
- *
34
- * @param txns Either [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed
35
- * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns),
36
- * or [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed
37
- * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).
38
- * @param onChanged A function to call when transaction manager reports iModel data changes.
39
- * @returns A function that unregisters the transaction manager listeners.
40
- * @public
41
- */
42
- function registerTxnListeners(txns, onChanged) {
43
- let hasChanges = false;
44
- const beforeCommit = txns.onCommit.addListener(() => {
45
- hasChanges = true;
46
- });
47
- const afterCommit = txns.onCommitted.addListener(() => {
48
- if (hasChanges) {
49
- onChanged();
50
- }
51
- hasChanges = false;
52
- });
53
- const appliedChanges = txns.onChangesApplied.addListener(onChanged);
54
- return () => {
55
- beforeCommit();
56
- afterCommit();
57
- appliedChanges();
58
- };
59
- }
60
- //# sourceMappingURL=Transactions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Transactions.js","sourceRoot":"","sources":["../../../src/core-interop/Transactions.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAwEhG,oDAiBC;AAnDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,SAAgB,oBAAoB,CAAC,IAAqB,EAAE,SAAqB;IAC/E,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;QAClD,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE;QACpD,IAAI,UAAU,EAAE,CAAC;YACf,SAAS,EAAE,CAAC;QACd,CAAC;QACD,UAAU,GAAG,KAAK,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACpE,OAAO,GAAG,EAAE;QACV,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,CAAC;QACd,cAAc,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,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 type { Event } from \"@itwin/presentation-shared\";\n\n/**\n * An interface for a transaction manager that has 3 types of events fired before and after a commit\n * and when changes are applied on a briefcase.\n *\n * Generally, this either means [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed\n * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns), or\n * [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed\n * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).\n * @public\n */\ninterface ICoreTxnManager {\n /**\n * Event raised before a commit operation is performed. Initiated by a call to either\n * [IModelDb.saveChanges](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/savechanges/)\n * or [BriefcaseConnection.saveChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/savechanges/),\n * unless there are no changes to save.\n */\n onCommit: Event;\n /**\n * Event raised after a commit operation is performed. Initiated by a call to either\n * [IModelDb.saveChanges](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/savechanges/)\n * or [BriefcaseConnection.saveChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/savechanges/),\n * even if there were no changes to save.\n */\n onCommitted: Event;\n /**\n * Event raised after a changeset has been applied to the briefcase. Changesets may be applied as a result of\n * [BriefcaseDb.pullChanges](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/) or\n * [BriefcaseConnection.pullChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/pullchanges/),\n * or by undo/redo operations.\n */\n onChangesApplied: Event;\n}\n\n/**\n * Registers listeners to `txns` events and calls provided `onChanged` callback when transaction manager\n * reports there are iModel data changes.\n *\n * Usage example:\n *\n * ```ts\n * import { BriefcaseDb } from \"@itwin/core-backend\";\n * import { registerTxnListeners } from \"@itwin/presentation-core-interop\";\n * import { HierarchyProvider } from \"@itwin/presentation-hierarchies\";\n *\n * // get iModel and hierarchy provider from arbitrary sources\n * const db: BriefcaseDb = getIModel();\n * const provider: HierarchyProvider = getHierarchyProvider();\n *\n * // register the listeners\n * const unregister = registerTxnListeners(db.txns, () => {\n * // notify provided about the changed data\n * provider.notifyDataSourceChanged();\n * // TODO: force the components using `provider` to reload\n * });\n *\n * // clean up on iModel close\n * db.onClosed.addOnce(() => unregister());\n * ```\n *\n * @param txns Either [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed\n * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns),\n * or [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed\n * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).\n * @param onChanged A function to call when transaction manager reports iModel data changes.\n * @returns A function that unregisters the transaction manager listeners.\n * @public\n */\nexport function registerTxnListeners(txns: ICoreTxnManager, onChanged: () => void): () => void {\n let hasChanges = false;\n const beforeCommit = txns.onCommit.addListener(() => {\n hasChanges = true;\n });\n const afterCommit = txns.onCommitted.addListener(() => {\n if (hasChanges) {\n onChanged();\n }\n hasChanges = false;\n });\n const appliedChanges = txns.onChangesApplied.addListener(onChanged);\n return () => {\n beforeCommit();\n afterCommit();\n appliedChanges();\n };\n}\n"]}
@@ -1 +0,0 @@
1
- { "type": "commonjs" }
@@ -1 +0,0 @@
1
- {"version":3,"file":"presentation-core-interop.d.ts","sourceRoot":"","sources":["../../src/presentation-core-interop.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -1,20 +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
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.registerTxnListeners = exports.createECSqlQueryExecutor = exports.createECSchemaProvider = exports.createLogger = exports.createIModelKey = exports.createValueFormatter = void 0;
8
- var Formatting_js_1 = require("./core-interop/Formatting.js");
9
- Object.defineProperty(exports, "createValueFormatter", { enumerable: true, get: function () { return Formatting_js_1.createValueFormatter; } });
10
- var IModelKey_js_1 = require("./core-interop/IModelKey.js");
11
- Object.defineProperty(exports, "createIModelKey", { enumerable: true, get: function () { return IModelKey_js_1.createIModelKey; } });
12
- var Logging_js_1 = require("./core-interop/Logging.js");
13
- Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return Logging_js_1.createLogger; } });
14
- var Metadata_js_1 = require("./core-interop/Metadata.js");
15
- Object.defineProperty(exports, "createECSchemaProvider", { enumerable: true, get: function () { return Metadata_js_1.createECSchemaProvider; } });
16
- var QueryExecutor_js_1 = require("./core-interop/QueryExecutor.js");
17
- Object.defineProperty(exports, "createECSqlQueryExecutor", { enumerable: true, get: function () { return QueryExecutor_js_1.createECSqlQueryExecutor; } });
18
- var Transactions_js_1 = require("./core-interop/Transactions.js");
19
- Object.defineProperty(exports, "registerTxnListeners", { enumerable: true, get: function () { return Transactions_js_1.registerTxnListeners; } });
20
- //# sourceMappingURL=presentation-core-interop.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"presentation-core-interop.js","sourceRoot":"","sources":["../../src/presentation-core-interop.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,8DAAoE;AAA3D,qHAAA,oBAAoB,OAAA;AAC7B,4DAA8D;AAArD,+GAAA,eAAe,OAAA;AACxB,wDAAyD;AAAhD,0GAAA,YAAY,OAAA;AACrB,0DAAoE;AAA3D,qHAAA,sBAAsB,OAAA;AAC/B,oEAA2E;AAAlE,4HAAA,wBAAwB,OAAA;AACjC,kEAAsE;AAA7D,uHAAA,oBAAoB,OAAA","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\nexport { createValueFormatter } from \"./core-interop/Formatting.js\";\nexport { createIModelKey } from \"./core-interop/IModelKey.js\";\nexport { createLogger } from \"./core-interop/Logging.js\";\nexport { createECSchemaProvider } from \"./core-interop/Metadata.js\";\nexport { createECSqlQueryExecutor } from \"./core-interop/QueryExecutor.js\";\nexport { registerTxnListeners } from \"./core-interop/Transactions.js\";\n"]}
@@ -1,45 +0,0 @@
1
- import type { UnitSystemKey } from "@itwin/core-quantity";
2
- import type { SchemaContext } from "@itwin/ecschema-metadata";
3
- import type { IPrimitiveValueFormatter } from "@itwin/presentation-shared";
4
- /**
5
- * Props for `createValueFormatter` function.
6
- * @public
7
- */
8
- interface CreateValueFormatterProps {
9
- /**
10
- * An instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/) for
11
- * getting units information. Generally, retrieved directly from `IModelDb` or `IModelConnection` using the `schemaContext` accessor.
12
- */
13
- schemaContext: SchemaContext;
14
- /**
15
- * An optional unit system to use for formatting property values. If not provided, default presentation units are used. If a property
16
- * doesn't have a default presentation unit, then persistence unit is used. Finally, if a property doesn't have a unit assigned at all,
17
- * `baseFormatter` is used to format the property value.
18
- */
19
- unitSystem?: UnitSystemKey;
20
- /**
21
- * Base primitive value formatter for cases when a property doesn't have any units' information. Defaults to the result of `createDefaultValueFormatter`
22
- * from `@itwin/presentation-shared` package.
23
- */
24
- baseFormatter?: IPrimitiveValueFormatter;
25
- }
26
- /**
27
- * Creates an instance of `IPrimitiveValueFormatter` that knows how to format values of properties with assigned kind of quantity. In
28
- * case the property does not have an assigned kind of quantity, the base formatter is used.
29
- *
30
- * Usage example:
31
- *
32
- * ```ts
33
- * import { IModelConnection } from "@itwin/core-frontend";
34
- * import { createValueFormatter } from "@itwin/presentation-core-interop";
35
- *
36
- * const imodel: IModelConnection = getIModel();
37
- * const formatter = createValueFormatter({ schemaContext: imodel.schemaContext, unitSystem: "metric" });
38
- * const formattedValue = await formatter({ type: "Double", value: 1.234, koqName: "MySchema.LengthKindOfQuantity" });
39
- * ```
40
- *
41
- * @public
42
- */
43
- export declare function createValueFormatter(props: CreateValueFormatterProps): IPrimitiveValueFormatter;
44
- export {};
45
- //# sourceMappingURL=Formatting.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Formatting.d.ts","sourceRoot":"","sources":["../../../src/core-interop/Formatting.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAA8B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAA0C,aAAa,EAAQ,MAAM,0BAA0B,CAAC;AAC5G,OAAO,KAAK,EAAE,wBAAwB,EAAuB,MAAM,4BAA4B,CAAC;AAEhG;;;GAGG;AACH,UAAU,yBAAyB;IACjC;;;OAGG;IACH,aAAa,EAAE,aAAa,CAAC;IAE7B;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;IAE3B;;;OAGG;IACH,aAAa,CAAC,EAAE,wBAAwB,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,wBAAwB,CAe/F"}
@@ -1,133 +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
- import { FormatterSpec, Format as QuantityFormat } from "@itwin/core-quantity";
6
- import { KindOfQuantity, OverrideFormat, SchemaKey, SchemaMatchType, SchemaUnitProvider, } from "@itwin/ecschema-metadata";
7
- import { createDefaultValueFormatter, parseFullClassName } from "@itwin/presentation-shared";
8
- /**
9
- * Creates an instance of `IPrimitiveValueFormatter` that knows how to format values of properties with assigned kind of quantity. In
10
- * case the property does not have an assigned kind of quantity, the base formatter is used.
11
- *
12
- * Usage example:
13
- *
14
- * ```ts
15
- * import { IModelConnection } from "@itwin/core-frontend";
16
- * import { createValueFormatter } from "@itwin/presentation-core-interop";
17
- *
18
- * const imodel: IModelConnection = getIModel();
19
- * const formatter = createValueFormatter({ schemaContext: imodel.schemaContext, unitSystem: "metric" });
20
- * const formattedValue = await formatter({ type: "Double", value: 1.234, koqName: "MySchema.LengthKindOfQuantity" });
21
- * ```
22
- *
23
- * @public
24
- */
25
- export function createValueFormatter(props) {
26
- const { schemaContext, unitSystem } = props;
27
- /* v8 ignore next -- @preserve */
28
- const baseFormatter = props.baseFormatter ?? createDefaultValueFormatter();
29
- const unitsProvider = new SchemaUnitProvider(schemaContext);
30
- return async function (value) {
31
- if (value.type === "Double" && !!value.koqName) {
32
- const koq = await getKindOfQuantity(schemaContext, value.koqName);
33
- const spec = await getFormatterSpec(unitsProvider, koq, unitSystem);
34
- if (spec) {
35
- return spec.applyFormatting(value.value);
36
- }
37
- }
38
- return baseFormatter(value);
39
- };
40
- }
41
- async function getKindOfQuantity(schemas, fullName) {
42
- const { schemaName, className: koqName } = parseFullClassName(fullName);
43
- const schema = await schemas.getSchema(new SchemaKey(schemaName), SchemaMatchType.Latest);
44
- if (!schema) {
45
- throw new Error(`Invalid schema "${schemaName}" specified in KoQ full name "${fullName}"`);
46
- }
47
- const koq = await schema.getItem(koqName, KindOfQuantity);
48
- if (!koq) {
49
- throw new Error(`Invalid kind of quantity "${koqName}" specified in KoQ full name "${fullName}" - it does not exist in schema "${schemaName}"`);
50
- }
51
- return koq;
52
- }
53
- async function getFormatterSpec(unitsProvider, koq, unitSystem) {
54
- const formattingProps = await getFormattingProps(koq, unitSystem);
55
- if (!formattingProps) {
56
- return undefined;
57
- }
58
- const { formatProps, persistenceUnitName } = formattingProps;
59
- const persistenceUnit = await unitsProvider.findUnitByName(persistenceUnitName);
60
- const format = await QuantityFormat.createFromJSON("", unitsProvider, formatProps);
61
- return FormatterSpec.create("", format, unitsProvider, persistenceUnit);
62
- }
63
- async function getFormattingProps(koq, unitSystem) {
64
- const persistenceUnit = await koq.persistenceUnit;
65
- if (!persistenceUnit) {
66
- return undefined;
67
- }
68
- const formatProps = await getKoqFormatProps(koq, persistenceUnit, unitSystem);
69
- if (!formatProps) {
70
- return undefined;
71
- }
72
- return { formatProps, persistenceUnitName: persistenceUnit.fullName };
73
- }
74
- async function getKoqFormatProps(koq, persistenceUnit, unitSystem) {
75
- const unitSystems = getUnitSystemGroupNames(unitSystem);
76
- // use one of KOQ presentation format that matches requested unit system
77
- const presentationFormat = await getKoqPresentationFormat(koq, unitSystems);
78
- if (presentationFormat) {
79
- return getFormatProps(presentationFormat);
80
- }
81
- // use persistence unit format if it matches requested unit system and matching presentation format was not found
82
- const persistenceUnitSystem = await persistenceUnit.unitSystem;
83
- if (persistenceUnitSystem && unitSystems.includes(persistenceUnitSystem.name.toUpperCase())) {
84
- return getPersistenceUnitFormatProps(persistenceUnit);
85
- }
86
- // use default presentation format if persistence unit does not match requested unit system
87
- if (koq.defaultPresentationFormat) {
88
- return getFormatProps(koq.defaultPresentationFormat);
89
- }
90
- return undefined;
91
- }
92
- async function getKoqPresentationFormat(koq, unitSystems) {
93
- const presentationFormats = koq.presentationFormats;
94
- for (const system of unitSystems) {
95
- for (const format of presentationFormats) {
96
- const units = format instanceof OverrideFormat ? format.units : (await format).units;
97
- const lazyUnit = units && units[0][0];
98
- const currentUnitSystem = lazyUnit && (await lazyUnit).unitSystem;
99
- if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {
100
- return format;
101
- }
102
- }
103
- }
104
- return undefined;
105
- }
106
- async function getFormatProps(format) {
107
- return format instanceof OverrideFormat ? format.getFormatProps() : (await format).toJSON();
108
- }
109
- function getPersistenceUnitFormatProps(persistenceUnit) {
110
- // Same as Format "DefaultRealU" in Formats ecschema
111
- return {
112
- formatTraits: ["keepSingleZero", "keepDecimalPoint", "showUnitLabel"],
113
- precision: 6,
114
- type: "Decimal",
115
- uomSeparator: " ",
116
- decimalSeparator: ".",
117
- composite: { units: [{ name: persistenceUnit.fullName, label: persistenceUnit.label }] },
118
- };
119
- }
120
- function getUnitSystemGroupNames(unitSystem) {
121
- switch (unitSystem) {
122
- case "imperial":
123
- return ["IMPERIAL", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
124
- case "metric":
125
- return ["SI", "METRIC", "INTERNATIONAL", "FINANCE"];
126
- case "usCustomary":
127
- return ["USCUSTOM", "INTERNATIONAL", "FINANCE"];
128
- case "usSurvey":
129
- return ["USSURVEY", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
130
- }
131
- return [];
132
- }
133
- //# sourceMappingURL=Formatting.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Formatting.js","sourceRoot":"","sources":["../../../src/core-interop/Formatting.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,eAAe,EACf,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AA+B7F;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC5C,iCAAiC;IACjC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,IAAI,2BAA2B,EAAE,CAAC;IAC3E,MAAM,aAAa,GAAG,IAAI,kBAAkB,CAAC,aAAa,CAAC,CAAC;IAC5D,OAAO,KAAK,WAAW,KAA0B;QAC/C,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/C,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAClE,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;YACpE,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9B,CA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U;YACb,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;QAC9D,KAAK,QAAQ;YACX,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;QACtD,KAAK,aAAa;YAChB,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;QAClD,KAAK,UAAU;YACb,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,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 { FormatterSpec, Format as QuantityFormat } from \"@itwin/core-quantity\";\nimport {\n KindOfQuantity,\n OverrideFormat,\n SchemaKey,\n SchemaMatchType,\n SchemaUnitProvider,\n} from \"@itwin/ecschema-metadata\";\nimport { createDefaultValueFormatter, parseFullClassName } from \"@itwin/presentation-shared\";\n\nimport type { FormatProps, UnitsProvider, UnitSystemKey } from \"@itwin/core-quantity\";\nimport type { Format, InvertedUnit, LazyLoadedFormat, SchemaContext, Unit } from \"@itwin/ecschema-metadata\";\nimport type { IPrimitiveValueFormatter, TypedPrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Props for `createValueFormatter` function.\n * @public\n */\ninterface CreateValueFormatterProps {\n /**\n * An instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/) for\n * getting units information. Generally, retrieved directly from `IModelDb` or `IModelConnection` using the `schemaContext` accessor.\n */\n schemaContext: SchemaContext;\n\n /**\n * An optional unit system to use for formatting property values. If not provided, default presentation units are used. If a property\n * doesn't have a default presentation unit, then persistence unit is used. Finally, if a property doesn't have a unit assigned at all,\n * `baseFormatter` is used to format the property value.\n */\n unitSystem?: UnitSystemKey;\n\n /**\n * Base primitive value formatter for cases when a property doesn't have any units' information. Defaults to the result of `createDefaultValueFormatter`\n * from `@itwin/presentation-shared` package.\n */\n baseFormatter?: IPrimitiveValueFormatter;\n}\n\n/**\n * Creates an instance of `IPrimitiveValueFormatter` that knows how to format values of properties with assigned kind of quantity. In\n * case the property does not have an assigned kind of quantity, the base formatter is used.\n *\n * Usage example:\n *\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * import { createValueFormatter } from \"@itwin/presentation-core-interop\";\n *\n * const imodel: IModelConnection = getIModel();\n * const formatter = createValueFormatter({ schemaContext: imodel.schemaContext, unitSystem: \"metric\" });\n * const formattedValue = await formatter({ type: \"Double\", value: 1.234, koqName: \"MySchema.LengthKindOfQuantity\" });\n * ```\n *\n * @public\n */\nexport function createValueFormatter(props: CreateValueFormatterProps): IPrimitiveValueFormatter {\n const { schemaContext, unitSystem } = props;\n /* v8 ignore next -- @preserve */\n const baseFormatter = props.baseFormatter ?? createDefaultValueFormatter();\n const unitsProvider = new SchemaUnitProvider(schemaContext);\n return async function (value: TypedPrimitiveValue): Promise<string> {\n if (value.type === \"Double\" && !!value.koqName) {\n const koq = await getKindOfQuantity(schemaContext, value.koqName);\n const spec = await getFormatterSpec(unitsProvider, koq, unitSystem);\n if (spec) {\n return spec.applyFormatting(value.value);\n }\n }\n return baseFormatter(value);\n };\n}\n\nasync function getKindOfQuantity(schemas: SchemaContext, fullName: string) {\n const { schemaName, className: koqName } = parseFullClassName(fullName);\n const schema = await schemas.getSchema(new SchemaKey(schemaName), SchemaMatchType.Latest);\n if (!schema) {\n throw new Error(`Invalid schema \"${schemaName}\" specified in KoQ full name \"${fullName}\"`);\n }\n const koq = await schema.getItem(koqName, KindOfQuantity);\n if (!koq) {\n throw new Error(\n `Invalid kind of quantity \"${koqName}\" specified in KoQ full name \"${fullName}\" - it does not exist in schema \"${schemaName}\"`,\n );\n }\n return koq;\n}\n\nasync function getFormatterSpec(unitsProvider: UnitsProvider, koq: KindOfQuantity, unitSystem?: UnitSystemKey) {\n const formattingProps = await getFormattingProps(koq, unitSystem);\n if (!formattingProps) {\n return undefined;\n }\n const { formatProps, persistenceUnitName } = formattingProps;\n const persistenceUnit = await unitsProvider.findUnitByName(persistenceUnitName);\n const format = await QuantityFormat.createFromJSON(\"\", unitsProvider, formatProps);\n return FormatterSpec.create(\"\", format, unitsProvider, persistenceUnit);\n}\n\ninterface FormattingProps {\n formatProps: FormatProps;\n persistenceUnitName: string;\n}\n\nasync function getFormattingProps(\n koq: KindOfQuantity,\n unitSystem?: UnitSystemKey,\n): Promise<FormattingProps | undefined> {\n const persistenceUnit = await koq.persistenceUnit;\n if (!persistenceUnit) {\n return undefined;\n }\n const formatProps = await getKoqFormatProps(koq, persistenceUnit, unitSystem);\n if (!formatProps) {\n return undefined;\n }\n return { formatProps, persistenceUnitName: persistenceUnit.fullName };\n}\n\nasync function getKoqFormatProps(\n koq: KindOfQuantity,\n persistenceUnit: Unit | InvertedUnit,\n unitSystem?: UnitSystemKey,\n) {\n const unitSystems = getUnitSystemGroupNames(unitSystem);\n // use one of KOQ presentation format that matches requested unit system\n const presentationFormat = await getKoqPresentationFormat(koq, unitSystems);\n if (presentationFormat) {\n return getFormatProps(presentationFormat);\n }\n\n // use persistence unit format if it matches requested unit system and matching presentation format was not found\n const persistenceUnitSystem = await persistenceUnit.unitSystem;\n if (persistenceUnitSystem && unitSystems.includes(persistenceUnitSystem.name.toUpperCase())) {\n return getPersistenceUnitFormatProps(persistenceUnit);\n }\n\n // use default presentation format if persistence unit does not match requested unit system\n if (koq.defaultPresentationFormat) {\n return getFormatProps(koq.defaultPresentationFormat);\n }\n\n return undefined;\n}\n\nasync function getKoqPresentationFormat(koq: KindOfQuantity, unitSystems: string[]) {\n const presentationFormats = koq.presentationFormats;\n for (const system of unitSystems) {\n for (const format of presentationFormats) {\n const units = format instanceof OverrideFormat ? format.units : (await format).units;\n const lazyUnit = units && units[0][0];\n const currentUnitSystem = lazyUnit && (await lazyUnit).unitSystem;\n if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {\n return format;\n }\n }\n }\n return undefined;\n}\n\nasync function getFormatProps(format: LazyLoadedFormat | OverrideFormat | Format): Promise<FormatProps> {\n return format instanceof OverrideFormat ? format.getFormatProps() : (await format).toJSON();\n}\n\nfunction getPersistenceUnitFormatProps(persistenceUnit: Unit | InvertedUnit): FormatProps {\n // Same as Format \"DefaultRealU\" in Formats ecschema\n return {\n formatTraits: [\"keepSingleZero\", \"keepDecimalPoint\", \"showUnitLabel\"],\n precision: 6,\n type: \"Decimal\",\n uomSeparator: \" \",\n decimalSeparator: \".\",\n composite: { units: [{ name: persistenceUnit.fullName, label: persistenceUnit.label }] },\n };\n}\n\nfunction getUnitSystemGroupNames(unitSystem?: UnitSystemKey) {\n switch (unitSystem) {\n case \"imperial\":\n return [\"IMPERIAL\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\n case \"metric\":\n return [\"SI\", \"METRIC\", \"INTERNATIONAL\", \"FINANCE\"];\n case \"usCustomary\":\n return [\"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\n case \"usSurvey\":\n return [\"USSURVEY\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"];\n }\n return [];\n}\n"]}
@@ -1,31 +0,0 @@
1
- /**
2
- * Defines input for `createIModelKey`. Generally, this is an instance of either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/)
3
- * or [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).
4
- * @public
5
- */
6
- interface CoreIModel {
7
- key: string;
8
- name: string;
9
- }
10
- /**
11
- * Attempts to create a unique identifier for the given iModel. In majority of cases that's going to be the `key` property, but if it's not
12
- * set (e.g. when using [BlankConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/blankconnection/)) - `name` property
13
- * is used instead. Finally, if both are empty - the function will throw an error.
14
- *
15
- * Example:
16
- *
17
- * ```ts
18
- * import { IModelConnection } from "@itwin/core-frontend";
19
- * import { createIModelKey } from "@itwin/presentation-core-interop";
20
- *
21
- * IModelConnection.onOpen.addListener((imodel: IModelConnection) => {
22
- * const key = createIModelKey(imodel);
23
- * console.log(`IModel opened: "${key}"`);
24
- * });
25
- * ```
26
- *
27
- * @public
28
- */
29
- export declare function createIModelKey(imodel: CoreIModel): string;
30
- export {};
31
- //# sourceMappingURL=IModelKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IModelKey.d.ts","sourceRoot":"","sources":["../../../src/core-interop/IModelKey.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAQ1D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"IModelKey.js","sourceRoot":"","sources":["../../../src/core-interop/IModelKey.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAYhG;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkB;IAChD,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;AACjE,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\n/**\n * Defines input for `createIModelKey`. 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 * @public\n */\ninterface CoreIModel {\n key: string;\n name: string;\n}\n\n/**\n * Attempts to create a unique identifier for the given iModel. In majority of cases that's going to be the `key` property, but if it's not\n * set (e.g. when using [BlankConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/blankconnection/)) - `name` property\n * is used instead. Finally, if both are empty - the function will throw an error.\n *\n * Example:\n *\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * import { createIModelKey } from \"@itwin/presentation-core-interop\";\n *\n * IModelConnection.onOpen.addListener((imodel: IModelConnection) => {\n * const key = createIModelKey(imodel);\n * console.log(`IModel opened: \"${key}\"`);\n * });\n * ```\n *\n * @public\n */\nexport function createIModelKey(imodel: CoreIModel): string {\n if (imodel.key.length) {\n return imodel.key;\n }\n if (imodel.name.length) {\n return imodel.name;\n }\n throw new Error(`Provided iModel doesn't have a key or name.`);\n}\n"]}
@@ -1,33 +0,0 @@
1
- import { LogLevel as CoreLogLevel } from "@itwin/core-bentley";
2
- import type { ILogger } from "@itwin/presentation-shared";
3
- /**
4
- * Defines input for `createLogger`. Generally, this is the [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/)
5
- * class from `@itwin/core-bentley` package.
6
- * @public
7
- */
8
- interface ICoreLogger {
9
- isEnabled(category: string, level: CoreLogLevel): boolean;
10
- logError(category: string, message: string): void;
11
- logWarning(category: string, message: string): void;
12
- logInfo(category: string, message: string): void;
13
- logTrace(category: string, message: string): void;
14
- }
15
- /**
16
- * Creates a presentation `ILogger` instance that forwards all logging calls to the
17
- * [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/) API.
18
- *
19
- * Usage example:
20
- *
21
- * ```ts
22
- * import { Logger } from "@itwin/core-bentley";
23
- * import { createLogger } from "@itwin/presentation-core-interop";
24
- * import { setLogger } from "@itwin/presentation-hierarchies";
25
- *
26
- * setLogger(createLogger(Logger));
27
- * ```
28
- *
29
- * @public
30
- */
31
- export declare function createLogger(coreLogger: ICoreLogger): ILogger;
32
- export {};
33
- //# sourceMappingURL=Logging.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logging.d.ts","sourceRoot":"","sources":["../../../src/core-interop/Logging.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,4BAA4B,CAAC;AAEpE;;;;GAIG;AACH,UAAU,WAAW;IACnB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC;IAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAQ7D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logging.js","sourceRoot":"","sources":["../../../src/core-interop/Logging.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAiB/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,UAAuB;IAClD,OAAO;QACL,SAAS,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;QACtF,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC;QAC/D,UAAU,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC;QACnE,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;QAC7D,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC;KAChE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAe;IACtC,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC,OAAO,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,YAAY,CAAC,KAAK,CAAC;IAC9B,CAAC;AACH,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 { LogLevel as CoreLogLevel } from \"@itwin/core-bentley\";\n\nimport type { ILogger, LogLevel } from \"@itwin/presentation-shared\";\n\n/**\n * Defines input for `createLogger`. Generally, this is the [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/)\n * class from `@itwin/core-bentley` package.\n * @public\n */\ninterface ICoreLogger {\n isEnabled(category: string, level: CoreLogLevel): boolean;\n logError(category: string, message: string): void;\n logWarning(category: string, message: string): void;\n logInfo(category: string, message: string): void;\n logTrace(category: string, message: string): void;\n}\n\n/**\n * Creates a presentation `ILogger` instance that forwards all logging calls to the\n * [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/) API.\n *\n * Usage example:\n *\n * ```ts\n * import { Logger } from \"@itwin/core-bentley\";\n * import { createLogger } from \"@itwin/presentation-core-interop\";\n * import { setLogger } from \"@itwin/presentation-hierarchies\";\n *\n * setLogger(createLogger(Logger));\n * ```\n *\n * @public\n */\nexport function createLogger(coreLogger: ICoreLogger): ILogger {\n return {\n isEnabled: (category, level) => coreLogger.isEnabled(category, getCoreLogLevel(level)),\n logError: (category, msg) => coreLogger.logError(category, msg),\n logWarning: (category, msg) => coreLogger.logWarning(category, msg),\n logInfo: (category, msg) => coreLogger.logInfo(category, msg),\n logTrace: (category, msg) => coreLogger.logTrace(category, msg),\n };\n}\n\nfunction getCoreLogLevel(level: LogLevel): CoreLogLevel {\n switch (level) {\n case \"error\":\n return CoreLogLevel.Error;\n case \"warning\":\n return CoreLogLevel.Warning;\n case \"info\":\n return CoreLogLevel.Info;\n case \"trace\":\n return CoreLogLevel.Trace;\n }\n}\n"]}
@@ -1,30 +0,0 @@
1
- import { SchemaKey as CoreSchemaKey } from "@itwin/ecschema-metadata";
2
- import type { Schema as CoreSchema } from "@itwin/ecschema-metadata";
3
- import type { ECSchemaProvider } from "@itwin/presentation-shared";
4
- /**
5
- * Defines input for `createECSchemaProvider`. Generally, this is an instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/)
6
- * class from `@itwin/ecschema-metadata` package.
7
- * @public
8
- */
9
- interface CoreSchemaContext {
10
- getSchema(key: CoreSchemaKey): Promise<CoreSchema | undefined>;
11
- }
12
- /**
13
- * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).
14
- *
15
- * Usage example:
16
- *
17
- * ```ts
18
- * import { IModelConnection } from "@itwin/core-frontend";
19
- * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
20
- *
21
- * const imodel: IModelConnection = getIModel();
22
- * const schemaProvider = createECSchemaProvider(imodel.schemaContext);
23
- * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
24
- * ```
25
- *
26
- * @public
27
- */
28
- export declare function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider;
29
- export {};
30
- //# sourceMappingURL=Metadata.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metadata.d.ts","sourceRoot":"","sources":["../../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAM,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEvE;;;;GAIG;AACH,UAAU,iBAAiB;IACzB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CAChE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,iBAAiB,GAAG,gBAAgB,CAkCzF"}
@@ -1,59 +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
- import { SchemaKey as CoreSchemaKey } from "@itwin/ecschema-metadata";
6
- import { createECSchema } from "./MetadataInternal.js";
7
- /**
8
- * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).
9
- *
10
- * Usage example:
11
- *
12
- * ```ts
13
- * import { IModelConnection } from "@itwin/core-frontend";
14
- * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
15
- *
16
- * const imodel: IModelConnection = getIModel();
17
- * const schemaProvider = createECSchemaProvider(imodel.schemaContext);
18
- * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
19
- * ```
20
- *
21
- * @public
22
- */
23
- export function createECSchemaProvider(schemaContext) {
24
- const schemaRequestsCache = new Map();
25
- async function getSchemaUnprotected(schemaName) {
26
- const coreSchema = await schemaContext.getSchema(new CoreSchemaKey(schemaName));
27
- return coreSchema ? createECSchema(coreSchema) : undefined;
28
- }
29
- async function getSchemaProtected(schemaName, handledExistingSchemaErrors) {
30
- // workaround for https://github.com/iTwin/itwinjs-core/issues/6542
31
- try {
32
- return await getSchemaUnprotected(schemaName);
33
- }
34
- catch (e) {
35
- /* v8 ignore else -- @preserve */
36
- if (e instanceof Error) {
37
- if (e.message.includes("already exists within this cache") && !handledExistingSchemaErrors.has(schemaName)) {
38
- handledExistingSchemaErrors.add(schemaName);
39
- return getSchemaProtected(schemaName, handledExistingSchemaErrors);
40
- }
41
- if (e.message.includes("schema not found")) {
42
- return undefined;
43
- }
44
- }
45
- throw e;
46
- }
47
- }
48
- return {
49
- async getSchema(name) {
50
- let promise = schemaRequestsCache.get(name);
51
- if (!promise) {
52
- promise = getSchemaProtected(name, new Set());
53
- schemaRequestsCache.set(name, promise);
54
- }
55
- return promise;
56
- },
57
- };
58
- }
59
- //# sourceMappingURL=Metadata.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAcvD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAgC;IACrE,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9E,KAAK,UAAU,oBAAoB,CAAC,UAAkB;QACpD,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;QAChF,OAAO,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;IACD,KAAK,UAAU,kBAAkB,CAAC,UAAkB,EAAE,2BAAwC;QAC5F,mEAAmE;QACnE,IAAI,CAAC;YACH,OAAO,MAAM,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,iCAAiC;YACjC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC3G,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAC5C,OAAO,kBAAkB,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;gBACrE,CAAC;gBACD,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBAC3C,OAAO,SAAS,CAAC;gBACnB,CAAC;YACH,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK,CAAC,SAAS,CAAC,IAAI;YAClB,IAAI,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;gBAC9C,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,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 { SchemaKey as CoreSchemaKey } from \"@itwin/ecschema-metadata\";\nimport { createECSchema } from \"./MetadataInternal.js\";\n\nimport type { Schema as CoreSchema } from \"@itwin/ecschema-metadata\";\nimport type { EC, ECSchemaProvider } from \"@itwin/presentation-shared\";\n\n/**\n * Defines input for `createECSchemaProvider`. Generally, this is an instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/)\n * class from `@itwin/ecschema-metadata` package.\n * @public\n */\ninterface CoreSchemaContext {\n getSchema(key: CoreSchemaKey): Promise<CoreSchema | undefined>;\n}\n\n/**\n * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).\n *\n * Usage example:\n *\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * import { createECSchemaProvider } from \"@itwin/presentation-core-interop\";\n *\n * const imodel: IModelConnection = getIModel();\n * const schemaProvider = createECSchemaProvider(imodel.schemaContext);\n * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages\n * ```\n *\n * @public\n */\nexport function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider {\n const schemaRequestsCache = new Map<string, Promise<EC.Schema | undefined>>();\n async function getSchemaUnprotected(schemaName: string) {\n const coreSchema = await schemaContext.getSchema(new CoreSchemaKey(schemaName));\n return coreSchema ? createECSchema(coreSchema) : undefined;\n }\n async function getSchemaProtected(schemaName: string, handledExistingSchemaErrors: Set<string>) {\n // workaround for https://github.com/iTwin/itwinjs-core/issues/6542\n try {\n return await getSchemaUnprotected(schemaName);\n } catch (e) {\n /* v8 ignore else -- @preserve */\n if (e instanceof Error) {\n if (e.message.includes(\"already exists within this cache\") && !handledExistingSchemaErrors.has(schemaName)) {\n handledExistingSchemaErrors.add(schemaName);\n return getSchemaProtected(schemaName, handledExistingSchemaErrors);\n }\n if (e.message.includes(\"schema not found\")) {\n return undefined;\n }\n }\n throw e;\n }\n }\n return {\n async getSchema(name) {\n let promise = schemaRequestsCache.get(name);\n if (!promise) {\n promise = getSchemaProtected(name, new Set());\n schemaRequestsCache.set(name, promise);\n }\n return promise;\n },\n };\n}\n"]}
@@ -1,10 +0,0 @@
1
- import { ECClass as CoreClass } from "@itwin/ecschema-metadata";
2
- import type { Property as CoreProperty, Schema as CoreSchema } from "@itwin/ecschema-metadata";
3
- import type { EC } from "@itwin/presentation-shared";
4
- /** @internal */
5
- export declare function createECSchema(schema: CoreSchema): EC.Schema;
6
- /** @internal */
7
- export declare function createECClass(coreClass: CoreClass, schema?: EC.Schema): EC.Class;
8
- /** @internal */
9
- export declare function createECProperty(coreProperty: CoreProperty, ecClass: EC.Class): EC.Property;
10
- //# sourceMappingURL=MetadataInternal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MetadataInternal.d.ts","sourceRoot":"","sources":["../../../src/core-interop/MetadataInternal.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAoD,MAAM,0BAA0B,CAAC;AAGlH,OAAO,KAAK,EAUV,QAAQ,IAAI,YAAY,EAIxB,MAAM,IAAI,UAAU,EAMrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAErD,gBAAgB;AAChB,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,EAAE,CAAC,MAAM,CAY5D;AA2BD,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,CAYhF;AA4GD,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,QAAQ,CAqB3F"}