@itwin/presentation-core-interop 0.1.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.
Files changed (129) hide show
  1. package/.mocharc.json +8 -0
  2. package/.nycrc +14 -0
  3. package/CHANGELOG.md +12 -0
  4. package/LICENSE.md +9 -0
  5. package/README.md +99 -0
  6. package/api/presentation-core-interop.api.md +38 -0
  7. package/api/presentation-core-interop.exports.csv +7 -0
  8. package/eslint.config.js +14 -0
  9. package/lib/cjs/core-interop/Formatting.d.ts +44 -0
  10. package/lib/cjs/core-interop/Formatting.d.ts.map +1 -0
  11. package/lib/cjs/core-interop/Formatting.js +147 -0
  12. package/lib/cjs/core-interop/Formatting.js.map +1 -0
  13. package/lib/cjs/core-interop/Logging.d.ts +32 -0
  14. package/lib/cjs/core-interop/Logging.d.ts.map +1 -0
  15. package/lib/cjs/core-interop/Logging.js +47 -0
  16. package/lib/cjs/core-interop/Logging.js.map +1 -0
  17. package/lib/cjs/core-interop/Metadata.d.ts +28 -0
  18. package/lib/cjs/core-interop/Metadata.d.ts.map +1 -0
  19. package/lib/cjs/core-interop/Metadata.js +51 -0
  20. package/lib/cjs/core-interop/Metadata.js.map +1 -0
  21. package/lib/cjs/core-interop/MetadataInternal.d.ts +9 -0
  22. package/lib/cjs/core-interop/MetadataInternal.d.ts.map +1 -0
  23. package/lib/cjs/core-interop/MetadataInternal.js +370 -0
  24. package/lib/cjs/core-interop/MetadataInternal.js.map +1 -0
  25. package/lib/cjs/core-interop/QueryExecutor.d.ts +31 -0
  26. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +1 -0
  27. package/lib/cjs/core-interop/QueryExecutor.js +112 -0
  28. package/lib/cjs/core-interop/QueryExecutor.js.map +1 -0
  29. package/lib/cjs/core-interop/Transactions.d.ts +70 -0
  30. package/lib/cjs/core-interop/Transactions.d.ts.map +1 -0
  31. package/lib/cjs/core-interop/Transactions.js +61 -0
  32. package/lib/cjs/core-interop/Transactions.js.map +1 -0
  33. package/lib/cjs/presentation-core-interop.d.ts +6 -0
  34. package/lib/cjs/presentation-core-interop.d.ts.map +1 -0
  35. package/lib/cjs/presentation-core-interop.js +18 -0
  36. package/lib/cjs/presentation-core-interop.js.map +1 -0
  37. package/lib/cjs/test/Formatting.test.d.ts +2 -0
  38. package/lib/cjs/test/Formatting.test.d.ts.map +1 -0
  39. package/lib/cjs/test/Formatting.test.js +282 -0
  40. package/lib/cjs/test/Formatting.test.js.map +1 -0
  41. package/lib/cjs/test/Logging.test.d.ts +2 -0
  42. package/lib/cjs/test/Logging.test.d.ts.map +1 -0
  43. package/lib/cjs/test/Logging.test.js +57 -0
  44. package/lib/cjs/test/Logging.test.js.map +1 -0
  45. package/lib/cjs/test/Metadata.test.d.ts +2 -0
  46. package/lib/cjs/test/Metadata.test.d.ts.map +1 -0
  47. package/lib/cjs/test/Metadata.test.js +676 -0
  48. package/lib/cjs/test/Metadata.test.js.map +1 -0
  49. package/lib/cjs/test/QueryExecutor.test.d.ts +2 -0
  50. package/lib/cjs/test/QueryExecutor.test.d.ts.map +1 -0
  51. package/lib/cjs/test/QueryExecutor.test.js +178 -0
  52. package/lib/cjs/test/QueryExecutor.test.js.map +1 -0
  53. package/lib/cjs/test/Transactions.test.d.ts +2 -0
  54. package/lib/cjs/test/Transactions.test.d.ts.map +1 -0
  55. package/lib/cjs/test/Transactions.test.js +73 -0
  56. package/lib/cjs/test/Transactions.test.js.map +1 -0
  57. package/lib/cjs/test/index.d.ts +2 -0
  58. package/lib/cjs/test/index.d.ts.map +1 -0
  59. package/lib/cjs/test/index.js +43 -0
  60. package/lib/cjs/test/index.js.map +1 -0
  61. package/lib/esm/core-interop/Formatting.d.ts +44 -0
  62. package/lib/esm/core-interop/Formatting.d.ts.map +1 -0
  63. package/lib/esm/core-interop/Formatting.js +143 -0
  64. package/lib/esm/core-interop/Formatting.js.map +1 -0
  65. package/lib/esm/core-interop/Logging.d.ts +32 -0
  66. package/lib/esm/core-interop/Logging.d.ts.map +1 -0
  67. package/lib/esm/core-interop/Logging.js +43 -0
  68. package/lib/esm/core-interop/Logging.js.map +1 -0
  69. package/lib/esm/core-interop/Metadata.d.ts +28 -0
  70. package/lib/esm/core-interop/Metadata.d.ts.map +1 -0
  71. package/lib/esm/core-interop/Metadata.js +47 -0
  72. package/lib/esm/core-interop/Metadata.js.map +1 -0
  73. package/lib/esm/core-interop/MetadataInternal.d.ts +9 -0
  74. package/lib/esm/core-interop/MetadataInternal.d.ts.map +1 -0
  75. package/lib/esm/core-interop/MetadataInternal.js +364 -0
  76. package/lib/esm/core-interop/MetadataInternal.js.map +1 -0
  77. package/lib/esm/core-interop/QueryExecutor.d.ts +31 -0
  78. package/lib/esm/core-interop/QueryExecutor.d.ts.map +1 -0
  79. package/lib/esm/core-interop/QueryExecutor.js +108 -0
  80. package/lib/esm/core-interop/QueryExecutor.js.map +1 -0
  81. package/lib/esm/core-interop/Transactions.d.ts +70 -0
  82. package/lib/esm/core-interop/Transactions.d.ts.map +1 -0
  83. package/lib/esm/core-interop/Transactions.js +57 -0
  84. package/lib/esm/core-interop/Transactions.js.map +1 -0
  85. package/lib/esm/presentation-core-interop.d.ts +6 -0
  86. package/lib/esm/presentation-core-interop.d.ts.map +1 -0
  87. package/lib/esm/presentation-core-interop.js +10 -0
  88. package/lib/esm/presentation-core-interop.js.map +1 -0
  89. package/lib/esm/test/Formatting.test.d.ts +2 -0
  90. package/lib/esm/test/Formatting.test.d.ts.map +1 -0
  91. package/lib/esm/test/Formatting.test.js +277 -0
  92. package/lib/esm/test/Formatting.test.js.map +1 -0
  93. package/lib/esm/test/Logging.test.d.ts +2 -0
  94. package/lib/esm/test/Logging.test.d.ts.map +1 -0
  95. package/lib/esm/test/Logging.test.js +52 -0
  96. package/lib/esm/test/Logging.test.js.map +1 -0
  97. package/lib/esm/test/Metadata.test.d.ts +2 -0
  98. package/lib/esm/test/Metadata.test.d.ts.map +1 -0
  99. package/lib/esm/test/Metadata.test.js +671 -0
  100. package/lib/esm/test/Metadata.test.js.map +1 -0
  101. package/lib/esm/test/QueryExecutor.test.d.ts +2 -0
  102. package/lib/esm/test/QueryExecutor.test.d.ts.map +1 -0
  103. package/lib/esm/test/QueryExecutor.test.js +173 -0
  104. package/lib/esm/test/QueryExecutor.test.js.map +1 -0
  105. package/lib/esm/test/Transactions.test.d.ts +2 -0
  106. package/lib/esm/test/Transactions.test.d.ts.map +1 -0
  107. package/lib/esm/test/Transactions.test.js +68 -0
  108. package/lib/esm/test/Transactions.test.js.map +1 -0
  109. package/lib/esm/test/index.d.ts +2 -0
  110. package/lib/esm/test/index.d.ts.map +1 -0
  111. package/lib/esm/test/index.js +15 -0
  112. package/lib/esm/test/index.js.map +1 -0
  113. package/package.json +72 -0
  114. package/src/core-interop/Formatting.ts +194 -0
  115. package/src/core-interop/Logging.ts +58 -0
  116. package/src/core-interop/Metadata.ts +56 -0
  117. package/src/core-interop/MetadataInternal.ts +413 -0
  118. package/src/core-interop/QueryExecutor.ts +122 -0
  119. package/src/core-interop/Transactions.ts +92 -0
  120. package/src/presentation-core-interop.ts +10 -0
  121. package/src/test/Formatting.test.ts +358 -0
  122. package/src/test/Logging.test.ts +59 -0
  123. package/src/test/Metadata.test.ts +776 -0
  124. package/src/test/QueryExecutor.test.ts +217 -0
  125. package/src/test/Transactions.test.ts +74 -0
  126. package/src/test/index.ts +17 -0
  127. package/tsconfig.cjs.json +7 -0
  128. package/tsconfig.esm.json +7 -0
  129. package/tsconfig.json +14 -0
@@ -0,0 +1,57 @@
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
+ /**
6
+ * Registers listeners to `txns` events and calls provided `onChanged` callback when transaction manager
7
+ * reports there are iModel data changes.
8
+ *
9
+ * Usage example:
10
+ *
11
+ * ```ts
12
+ * import { BriefcaseDb } from "@itwin/core-backend";
13
+ * import { registerTxnListeners } from "@itwin/presentation-core-interop";
14
+ * import { HierarchyProvider } from "@itwin/presentation-hierarchies";
15
+ *
16
+ * // get iModel and hierarchy provider from arbitrary sources
17
+ * const db: BriefcaseDb = getIModel();
18
+ * const provider: HierarchyProvider = getHierarchyProvider();
19
+ *
20
+ * // register the listeners
21
+ * const unregister = registerTxnListeners(db.txns, () => {
22
+ * // notify provided about the changed data
23
+ * provider.notifyDataSourceChanged();
24
+ * // TODO: force the components using `provider` to reload
25
+ * });
26
+ *
27
+ * // clean up on iModel close
28
+ * db.onClosed.addOnce(() => unregister());
29
+ * ```
30
+ *
31
+ * @param txns Either [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed
32
+ * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns),
33
+ * or [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed
34
+ * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).
35
+ * @param onChanged A function to call when transaction manager reports iModel data changes.
36
+ * @returns A function that unregisters the transaction manager listeners.
37
+ * @beta
38
+ */
39
+ export function registerTxnListeners(txns, onChanged) {
40
+ let hasChanges = false;
41
+ const beforeCommit = txns.onCommit.addListener(() => {
42
+ hasChanges = true;
43
+ });
44
+ const afterCommit = txns.onCommitted.addListener(() => {
45
+ if (hasChanges) {
46
+ onChanged();
47
+ }
48
+ hasChanges = false;
49
+ });
50
+ const appliedChanges = txns.onChangesApplied.addListener(onChanged);
51
+ return () => {
52
+ beforeCommit();
53
+ afterCommit();
54
+ appliedChanges();
55
+ };
56
+ }
57
+ //# sourceMappingURL=Transactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transactions.js","sourceRoot":"","sources":["../../../src/core-interop/Transactions.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAqChG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,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 { 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 */\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 * @beta\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"]}
@@ -0,0 +1,6 @@
1
+ export { createValueFormatter } from "./core-interop/Formatting";
2
+ export { createLogger } from "./core-interop/Logging";
3
+ export { createECSchemaProvider } from "./core-interop/Metadata";
4
+ export { createECSqlQueryExecutor } from "./core-interop/QueryExecutor";
5
+ export { registerTxnListeners } from "./core-interop/Transactions";
6
+ //# sourceMappingURL=presentation-core-interop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-core-interop.d.ts","sourceRoot":"","sources":["../../src/presentation-core-interop.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,10 @@
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
+ export { createValueFormatter } from "./core-interop/Formatting";
6
+ export { createLogger } from "./core-interop/Logging";
7
+ export { createECSchemaProvider } from "./core-interop/Metadata";
8
+ export { createECSqlQueryExecutor } from "./core-interop/QueryExecutor";
9
+ export { registerTxnListeners } from "./core-interop/Transactions";
10
+ //# sourceMappingURL=presentation-core-interop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-core-interop.js","sourceRoot":"","sources":["../../src/presentation-core-interop.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,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\nexport { createValueFormatter } from \"./core-interop/Formatting\";\nexport { createLogger } from \"./core-interop/Logging\";\nexport { createECSchemaProvider } from \"./core-interop/Metadata\";\nexport { createECSqlQueryExecutor } from \"./core-interop/QueryExecutor\";\nexport { registerTxnListeners } from \"./core-interop/Transactions\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Formatting.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Formatting.test.d.ts","sourceRoot":"","sources":["../../../src/test/Formatting.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,277 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { expect } from "chai";
6
+ import sinon from "sinon";
7
+ import { FormatterSpec, Format as QuantityFormat } from "@itwin/core-quantity";
8
+ import { OverrideFormat, SchemaItemType, SchemaUnitProvider, } from "@itwin/ecschema-metadata";
9
+ import { createValueFormatter } from "../core-interop/Formatting";
10
+ describe("createValueFormatter", () => {
11
+ const schemaContext = {
12
+ getSchema: sinon.stub(),
13
+ };
14
+ const defaultFormatter = sinon.fake(async () => Promise.resolve("DEFAULT"));
15
+ let formatter;
16
+ function initFormatter(unitSystem) {
17
+ formatter = createValueFormatter({
18
+ schemaContext: schemaContext,
19
+ unitSystem,
20
+ baseFormatter: defaultFormatter,
21
+ });
22
+ }
23
+ beforeEach(() => {
24
+ defaultFormatter.resetHistory();
25
+ initFormatter();
26
+ });
27
+ it("returns default formatter result when property doesn't have a KoQ", async () => {
28
+ const prop = {
29
+ type: "Double",
30
+ value: 1.23,
31
+ };
32
+ expect(await formatter(prop)).to.eq("DEFAULT");
33
+ expect(defaultFormatter).to.be.calledOnceWith(prop);
34
+ });
35
+ it("throws when property references non-existing schema in KoQ", async () => {
36
+ schemaContext.getSchema.resolves(undefined);
37
+ const prop = {
38
+ type: "Double",
39
+ value: 1.23,
40
+ koqName: "X.Y",
41
+ };
42
+ await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid schema");
43
+ });
44
+ it("throws when property references non-existing KoQ", async () => {
45
+ schemaContext.getSchema.resolves({
46
+ name: "X",
47
+ getItem: async () => undefined,
48
+ });
49
+ const prop = {
50
+ type: "Double",
51
+ value: 1.23,
52
+ koqName: "X.Y",
53
+ };
54
+ await expect(formatter(prop)).to.eventually.be.rejectedWith("Invalid kind of quantity");
55
+ });
56
+ it("returns default formatter result when KoQ doesn't specify persistence unit", async () => {
57
+ schemaContext.getSchema.resolves({
58
+ name: "X",
59
+ getItem: async (name) => {
60
+ if (name === "Y") {
61
+ return {
62
+ persistenceUnit: Promise.resolve(undefined),
63
+ };
64
+ }
65
+ return undefined;
66
+ },
67
+ });
68
+ const prop = {
69
+ type: "Double",
70
+ value: 1.23,
71
+ koqName: "X.Y",
72
+ };
73
+ expect(await formatter(prop)).to.eq("DEFAULT");
74
+ expect(defaultFormatter).to.be.calledOnceWith(prop);
75
+ });
76
+ it("returns default formatter result when KoQ doesn't specify presentation format", async () => {
77
+ schemaContext.getSchema.resolves({
78
+ name: "X",
79
+ getItem: async (name) => {
80
+ if (name === "Y") {
81
+ return {
82
+ persistenceUnit: Promise.resolve({
83
+ unitSystem: Promise.resolve({
84
+ name: "metric",
85
+ }),
86
+ }),
87
+ presentationFormats: [],
88
+ defaultPresentationFormat: undefined,
89
+ };
90
+ }
91
+ return undefined;
92
+ },
93
+ });
94
+ const prop = {
95
+ type: "Double",
96
+ value: 1.23,
97
+ koqName: "X.Y",
98
+ };
99
+ expect(await formatter(prop)).to.eq("DEFAULT");
100
+ expect(defaultFormatter).to.be.calledOnceWith(prop);
101
+ });
102
+ it("returns koq formatter result when presentation format is found in koq formats list", async () => {
103
+ initFormatter("metric");
104
+ const persistenceUnit = createUnit("schema.persistence_unit", "metric");
105
+ const presentationUnit = createUnit("schema.presentation_unit", "metric");
106
+ const presentationFormatProps = {};
107
+ schemaContext.getSchema.resolves({
108
+ name: "schema",
109
+ getItem: async (name) => {
110
+ if (name === "koq") {
111
+ return {
112
+ schemaItemType: SchemaItemType.KindOfQuantity,
113
+ persistenceUnit: Promise.resolve(persistenceUnit),
114
+ presentationFormats: [
115
+ {
116
+ units: [[presentationUnit, "presentation unit"]],
117
+ toJSON: () => presentationFormatProps,
118
+ },
119
+ ],
120
+ defaultPresentationFormat: undefined,
121
+ };
122
+ }
123
+ if (name === "persistence_unit") {
124
+ return persistenceUnit;
125
+ }
126
+ if (name === "presentation_unit") {
127
+ return presentationUnit;
128
+ }
129
+ return undefined;
130
+ },
131
+ });
132
+ const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
133
+ const quantityFormat = {};
134
+ const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
135
+ const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
136
+ applyFormatting: koqFormatterStub,
137
+ });
138
+ expect(await formatter({
139
+ type: "Double",
140
+ value: 1.23,
141
+ koqName: "schema.koq",
142
+ })).to.eq("KOQ FORMAT");
143
+ expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), presentationFormatProps);
144
+ expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
145
+ expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
146
+ });
147
+ it("returns koq formatter result when persistence unit system matches requested unit system", async () => {
148
+ initFormatter("imperial");
149
+ const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
150
+ schemaContext.getSchema.resolves({
151
+ name: "schema",
152
+ getItem: async (name) => {
153
+ if (name === "koq") {
154
+ return {
155
+ schemaItemType: SchemaItemType.KindOfQuantity,
156
+ persistenceUnit: Promise.resolve(persistenceUnit),
157
+ presentationFormats: [],
158
+ defaultPresentationFormat: undefined,
159
+ };
160
+ }
161
+ if (name === "persistence_unit") {
162
+ return persistenceUnit;
163
+ }
164
+ return undefined;
165
+ },
166
+ });
167
+ const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
168
+ const quantityFormat = {};
169
+ const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
170
+ const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
171
+ applyFormatting: koqFormatterStub,
172
+ });
173
+ expect(await formatter({
174
+ type: "Double",
175
+ value: 1.23,
176
+ koqName: "schema.koq",
177
+ })).to.eq("KOQ FORMAT");
178
+ expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.composite.units[0].name === persistenceUnit.fullName));
179
+ expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
180
+ expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
181
+ });
182
+ it("returns koq formatter result when default presentation unit is of requested unit system", async () => {
183
+ initFormatter("usCustomary");
184
+ const persistenceUnit = createUnit("schema.persistence_unit", "imperial");
185
+ const defaultPresentationUnit = createUnit("schema.presentation_unit", "usCustomary");
186
+ const defaultPresentationFormatProps = {};
187
+ schemaContext.getSchema.resolves({
188
+ name: "schema",
189
+ getItem: async (name) => {
190
+ if (name === "koq") {
191
+ return {
192
+ schemaItemType: SchemaItemType.KindOfQuantity,
193
+ persistenceUnit: Promise.resolve(persistenceUnit),
194
+ presentationFormats: [],
195
+ defaultPresentationFormat: {
196
+ units: [[defaultPresentationUnit, "presentation unit"]],
197
+ toJSON: () => defaultPresentationFormatProps,
198
+ },
199
+ };
200
+ }
201
+ if (name === "persistence_unit") {
202
+ return persistenceUnit;
203
+ }
204
+ if (name === "presentation_unit") {
205
+ return defaultPresentationUnit;
206
+ }
207
+ return undefined;
208
+ },
209
+ });
210
+ const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
211
+ const quantityFormat = {};
212
+ const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
213
+ const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
214
+ applyFormatting: koqFormatterStub,
215
+ });
216
+ expect(await formatter({
217
+ type: "Double",
218
+ value: 1.23,
219
+ koqName: "schema.koq",
220
+ })).to.eq("KOQ FORMAT");
221
+ expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), defaultPresentationFormatProps);
222
+ expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
223
+ expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
224
+ });
225
+ it("returns koq formatter result when koq uses override format", async () => {
226
+ initFormatter("usSurvey");
227
+ const persistenceUnit = createUnit("schema.persistence_unit", "metric");
228
+ const presentationUnit = createUnit("schema.presentation_unit", "usSurvey");
229
+ const overrideFormat = new OverrideFormat({ fullName: "schema.base_format", toJSON: () => ({}) }, undefined, [
230
+ [presentationUnit, "presentation unit"],
231
+ ]);
232
+ schemaContext.getSchema.resolves({
233
+ name: "schema",
234
+ getItem: async (name) => {
235
+ if (name === "koq") {
236
+ return {
237
+ schemaItemType: SchemaItemType.KindOfQuantity,
238
+ persistenceUnit: Promise.resolve(persistenceUnit),
239
+ presentationFormats: [],
240
+ defaultPresentationFormat: overrideFormat,
241
+ };
242
+ }
243
+ if (name === "persistence_unit") {
244
+ return persistenceUnit;
245
+ }
246
+ if (name === "presentation_unit") {
247
+ return presentationUnit;
248
+ }
249
+ return undefined;
250
+ },
251
+ });
252
+ const koqFormatterStub = sinon.stub().returns("KOQ FORMAT");
253
+ const quantityFormat = {};
254
+ const createQuantityFormatStub = sinon.stub(QuantityFormat, "createFromJSON").resolves(quantityFormat);
255
+ const createFormatSpecStub = sinon.stub(FormatterSpec, "create").resolves({
256
+ applyFormatting: koqFormatterStub,
257
+ });
258
+ expect(await formatter({
259
+ type: "Double",
260
+ value: 1.23,
261
+ koqName: "schema.koq",
262
+ })).to.eq("KOQ FORMAT");
263
+ expect(createQuantityFormatStub).to.be.calledOnceWithExactly("", sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.composite?.units[0].name === presentationUnit.fullName));
264
+ expect(createFormatSpecStub).to.be.calledOnceWithExactly("", quantityFormat, sinon.match((arg) => arg instanceof SchemaUnitProvider), sinon.match((arg) => arg.name === persistenceUnit.fullName));
265
+ expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);
266
+ });
267
+ });
268
+ function createUnit(fullName, unitSystem) {
269
+ return {
270
+ schemaItemType: SchemaItemType.Unit,
271
+ fullName,
272
+ unitSystem: Promise.resolve({
273
+ name: unitSystem,
274
+ }),
275
+ };
276
+ }
277
+ //# sourceMappingURL=Formatting.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Formatting.test.js","sourceRoot":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ent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport sinon from \"sinon\";\nimport { FormatProps, FormatterSpec, Format as QuantityFormat, UnitSystemKey } from \"@itwin/core-quantity\";\nimport {\n Format,\n KindOfQuantity,\n OverrideFormat,\n Schema,\n SchemaContext,\n SchemaItemFormatProps,\n SchemaItemType,\n SchemaKey,\n SchemaUnitProvider,\n Unit,\n UnitSystem,\n} from \"@itwin/ecschema-metadata\";\nimport { IPrimitiveValueFormatter, TypedPrimitiveValue } from \"@itwin/presentation-shared\";\nimport { createValueFormatter } from \"../core-interop/Formatting\";\n\ndescribe(\"createValueFormatter\", () => {\n const schemaContext = {\n getSchema: sinon.stub<[SchemaKey], Schema>(),\n };\n const defaultFormatter = sinon.fake(async () => Promise.resolve(\"DEFAULT\"));\n let formatter: IPrimitiveValueFormatter;\n\n function initFormatter(unitSystem?: UnitSystemKey) {\n formatter = createValueFormatter({\n schemaContext: schemaContext as unknown as SchemaContext,\n unitSystem,\n baseFormatter: defaultFormatter,\n });\n }\n\n beforeEach(() => {\n defaultFormatter.resetHistory();\n initFormatter();\n });\n\n it(\"returns default formatter result when property doesn't have a KoQ\", async () => {\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"throws when property references non-existing schema in KoQ\", async () => {\n schemaContext.getSchema.resolves(undefined);\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n await expect(formatter(prop)).to.eventually.be.rejectedWith(\"Invalid schema\");\n });\n\n it(\"throws when property references non-existing KoQ\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async () => undefined,\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n await expect(formatter(prop)).to.eventually.be.rejectedWith(\"Invalid kind of quantity\");\n });\n\n it(\"returns default formatter result when KoQ doesn't specify persistence unit\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async (name: string) => {\n if (name === \"Y\") {\n return {\n persistenceUnit: Promise.resolve(undefined),\n } as unknown as KindOfQuantity;\n }\n return undefined;\n },\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"returns default formatter result when KoQ doesn't specify presentation format\", async () => {\n schemaContext.getSchema.resolves({\n name: \"X\",\n getItem: async (name: string) => {\n if (name === \"Y\") {\n return {\n persistenceUnit: Promise.resolve({\n unitSystem: Promise.resolve({\n name: \"metric\",\n } as UnitSystem),\n } as Unit),\n presentationFormats: [],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n return undefined;\n },\n });\n const prop: TypedPrimitiveValue = {\n type: \"Double\",\n value: 1.23,\n koqName: \"X.Y\",\n };\n expect(await formatter(prop)).to.eq(\"DEFAULT\");\n expect(defaultFormatter).to.be.calledOnceWith(prop);\n });\n\n it(\"returns koq formatter result when presentation format is found in koq formats list\", async () => {\n initFormatter(\"metric\");\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"metric\");\n const presentationUnit = createUnit(\"schema.presentation_unit\", \"metric\");\n const presentationFormatProps = {} as SchemaItemFormatProps;\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [\n {\n units: [[presentationUnit, \"presentation unit\"]],\n toJSON: () => presentationFormatProps,\n } as unknown as Format,\n ],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return presentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n presentationFormatProps,\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when persistence unit system matches requested unit system\", async () => {\n initFormatter(\"imperial\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"imperial\");\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: undefined,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg: SchemaItemFormatProps) => arg.composite!.units[0].name === persistenceUnit.fullName),\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when default presentation unit is of requested unit system\", async () => {\n initFormatter(\"usCustomary\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"imperial\");\n const defaultPresentationUnit = createUnit(\"schema.presentation_unit\", \"usCustomary\");\n const defaultPresentationFormatProps = {} as SchemaItemFormatProps;\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: {\n units: [[defaultPresentationUnit, \"presentation unit\"]],\n toJSON: () => defaultPresentationFormatProps,\n } as unknown as Format,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return defaultPresentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n defaultPresentationFormatProps,\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n\n it(\"returns koq formatter result when koq uses override format\", async () => {\n initFormatter(\"usSurvey\");\n\n const persistenceUnit = createUnit(\"schema.persistence_unit\", \"metric\");\n const presentationUnit = createUnit(\"schema.presentation_unit\", \"usSurvey\");\n const overrideFormat = new OverrideFormat({ fullName: \"schema.base_format\", toJSON: () => ({}) } as Format, undefined, [\n [presentationUnit, \"presentation unit\"],\n ]);\n schemaContext.getSchema.resolves({\n name: \"schema\",\n getItem: async (name: string) => {\n if (name === \"koq\") {\n return {\n schemaItemType: SchemaItemType.KindOfQuantity,\n persistenceUnit: Promise.resolve(persistenceUnit),\n presentationFormats: [],\n defaultPresentationFormat: overrideFormat,\n } as unknown as KindOfQuantity;\n }\n if (name === \"persistence_unit\") {\n return persistenceUnit;\n }\n if (name === \"presentation_unit\") {\n return presentationUnit;\n }\n return undefined;\n },\n });\n\n const koqFormatterStub = sinon.stub().returns(\"KOQ FORMAT\");\n const quantityFormat = {} as unknown as QuantityFormat;\n const createQuantityFormatStub = sinon.stub(QuantityFormat, \"createFromJSON\").resolves(quantityFormat);\n const createFormatSpecStub = sinon.stub(FormatterSpec, \"create\").resolves({\n applyFormatting: koqFormatterStub,\n } as unknown as FormatterSpec);\n\n expect(\n await formatter({\n type: \"Double\",\n value: 1.23,\n koqName: \"schema.koq\",\n }),\n ).to.eq(\"KOQ FORMAT\");\n expect(createQuantityFormatStub).to.be.calledOnceWithExactly(\n \"\",\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg: FormatProps) => arg.composite?.units[0].name === presentationUnit.fullName),\n );\n expect(createFormatSpecStub).to.be.calledOnceWithExactly(\n \"\",\n quantityFormat,\n sinon.match((arg) => arg instanceof SchemaUnitProvider),\n sinon.match((arg) => arg.name === persistenceUnit.fullName),\n );\n expect(koqFormatterStub).to.be.calledOnceWithExactly(1.23);\n });\n});\n\nfunction createUnit(fullName: string, unitSystem: UnitSystemKey) {\n return {\n schemaItemType: SchemaItemType.Unit,\n fullName,\n unitSystem: Promise.resolve({\n name: unitSystem,\n } as UnitSystem),\n } as unknown as Unit;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Logging.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logging.test.d.ts","sourceRoot":"","sources":["../../../src/test/Logging.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { expect } from "chai";
6
+ import sinon from "sinon";
7
+ import { Logger, LogLevel } from "@itwin/core-bentley";
8
+ import { createLogger } from "../core-interop/Logging";
9
+ describe("createLogger", () => {
10
+ it("checks error severity using core `Logger`", async () => {
11
+ const spy = sinon.stub(Logger, "isEnabled").returns(true);
12
+ const logger = createLogger(Logger);
13
+ expect(logger.isEnabled("test category", "error")).to.be.true;
14
+ expect(spy).to.be.calledOnceWith("test category", LogLevel.Error);
15
+ });
16
+ it("checks warning severity using core `Logger`", async () => {
17
+ const spy = sinon.stub(Logger, "isEnabled").returns(true);
18
+ const logger = createLogger(Logger);
19
+ expect(logger.isEnabled("test category", "warning")).to.be.true;
20
+ expect(spy).to.be.calledOnceWith("test category", LogLevel.Warning);
21
+ });
22
+ it("checks info severity using core `Logger`", async () => {
23
+ const spy = sinon.stub(Logger, "isEnabled").returns(true);
24
+ const logger = createLogger(Logger);
25
+ expect(logger.isEnabled("test category", "info")).to.be.true;
26
+ expect(spy).to.be.calledOnceWith("test category", LogLevel.Info);
27
+ });
28
+ it("checks trace severity using core `Logger`", async () => {
29
+ const spy = sinon.stub(Logger, "isEnabled").returns(true);
30
+ const logger = createLogger(Logger);
31
+ expect(logger.isEnabled("test category", "trace")).to.be.true;
32
+ expect(spy).to.be.calledOnceWith("test category", LogLevel.Trace);
33
+ });
34
+ it("logs messages using core `Logger`", async () => {
35
+ const spies = {
36
+ error: sinon.spy(Logger, "logError"),
37
+ warn: sinon.spy(Logger, "logWarning"),
38
+ info: sinon.spy(Logger, "logInfo"),
39
+ trace: sinon.spy(Logger, "logTrace"),
40
+ };
41
+ const logger = createLogger(Logger);
42
+ logger.logError("c1", "m1");
43
+ logger.logWarning("c2", "m2");
44
+ logger.logInfo("c3", "m3");
45
+ logger.logTrace("c4", "m4");
46
+ expect(spies.error).to.be.calledOnceWithExactly("c1", "m1");
47
+ expect(spies.warn).to.be.calledOnceWithExactly("c2", "m2");
48
+ expect(spies.info).to.be.calledOnceWithExactly("c3", "m3");
49
+ expect(spies.trace).to.be.calledOnceWithExactly("c4", "m4");
50
+ });
51
+ });
52
+ //# sourceMappingURL=Logging.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logging.test.js","sourceRoot":"","sources":["../../../src/test/Logging.test.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI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AAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { expect } from \"chai\";\nimport sinon from \"sinon\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { createLogger } from \"../core-interop/Logging\";\n\ndescribe(\"createLogger\", () => {\n it(\"checks error severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"error\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Error);\n });\n\n it(\"checks warning severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"warning\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Warning);\n });\n\n it(\"checks info severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"info\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Info);\n });\n\n it(\"checks trace severity using core `Logger`\", async () => {\n const spy = sinon.stub(Logger, \"isEnabled\").returns(true);\n const logger = createLogger(Logger);\n expect(logger.isEnabled(\"test category\", \"trace\")).to.be.true;\n expect(spy).to.be.calledOnceWith(\"test category\", LogLevel.Trace);\n });\n\n it(\"logs messages using core `Logger`\", async () => {\n const spies = {\n error: sinon.spy(Logger, \"logError\"),\n warn: sinon.spy(Logger, \"logWarning\"),\n info: sinon.spy(Logger, \"logInfo\"),\n trace: sinon.spy(Logger, \"logTrace\"),\n };\n const logger = createLogger(Logger);\n\n logger.logError(\"c1\", \"m1\");\n logger.logWarning(\"c2\", \"m2\");\n logger.logInfo(\"c3\", \"m3\");\n logger.logTrace(\"c4\", \"m4\");\n\n expect(spies.error).to.be.calledOnceWithExactly(\"c1\", \"m1\");\n expect(spies.warn).to.be.calledOnceWithExactly(\"c2\", \"m2\");\n expect(spies.info).to.be.calledOnceWithExactly(\"c3\", \"m3\");\n expect(spies.trace).to.be.calledOnceWithExactly(\"c4\", \"m4\");\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Metadata.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Metadata.test.d.ts","sourceRoot":"","sources":["../../../src/test/Metadata.test.ts"],"names":[],"mappings":""}