@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,143 @@
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 { 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 { SchemaContext } from "@itwin/ecschema-metadata";
16
+ * import { createValueFormatter } from "@itwin/presentation-core-interop";
17
+ *
18
+ * const schemaContext = new SchemaContext();
19
+ * const formatter = createValueFormatter({ schemaContext, unitSystem: "metric" });
20
+ * const formattedValue = await formatter({ type: "Double", value: 1.234, koqName: "MySchema.LengthKindOfQuantity" });
21
+ * ```
22
+ *
23
+ * @beta
24
+ */
25
+ export function createValueFormatter(props) {
26
+ const { schemaContext, unitSystem } = props;
27
+ const baseFormatter = props.baseFormatter ?? /* istanbul ignore next */ createDefaultValueFormatter();
28
+ const unitsProvider = new SchemaUnitProvider(schemaContext);
29
+ return async function (value) {
30
+ if (value.type === "Double" && !!value.koqName) {
31
+ const koq = await getKindOfQuantity(schemaContext, value.koqName);
32
+ const spec = await getFormatterSpec(unitsProvider, koq, unitSystem);
33
+ if (spec) {
34
+ return spec.applyFormatting(value.value);
35
+ }
36
+ }
37
+ return baseFormatter(value);
38
+ };
39
+ }
40
+ async function getKindOfQuantity(schemas, fullName) {
41
+ const { schemaName, className: koqName } = parseFullClassName(fullName);
42
+ const schema = await schemas.getSchema(new SchemaKey(schemaName), SchemaMatchType.Latest);
43
+ if (!schema) {
44
+ throw new Error(`Invalid schema "${schemaName}" specified in KoQ full name "${fullName}"`);
45
+ }
46
+ const koq = await schema.getItem(koqName);
47
+ if (!koq) {
48
+ throw new Error(`Invalid kind of quantity "${koqName}" specified in KoQ full name "${fullName}" - it does not exist in schema "${schemaName}"`);
49
+ }
50
+ return koq;
51
+ }
52
+ async function getFormatterSpec(unitsProvider, koq, unitSystem) {
53
+ const formattingProps = await getFormattingProps(koq, unitSystem);
54
+ if (!formattingProps) {
55
+ return undefined;
56
+ }
57
+ const { formatProps, persistenceUnitName } = formattingProps;
58
+ const persistenceUnit = await unitsProvider.findUnitByName(persistenceUnitName);
59
+ const format = await QuantityFormat.createFromJSON("", unitsProvider, formatProps);
60
+ return FormatterSpec.create("", format, unitsProvider, persistenceUnit);
61
+ }
62
+ async function getFormattingProps(koq, unitSystem) {
63
+ const persistenceUnit = await koq.persistenceUnit;
64
+ // istanbul ignore if
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 unit = format.units && format.units[0][0];
97
+ // istanbul ignore if
98
+ if (!unit) {
99
+ continue;
100
+ }
101
+ const currentUnitSystem = await unit.unitSystem;
102
+ if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {
103
+ return format;
104
+ }
105
+ }
106
+ }
107
+ return undefined;
108
+ }
109
+ function getFormatProps(format) {
110
+ return format instanceof OverrideFormat ? format.getFormatProps() : format.toJSON();
111
+ }
112
+ function getPersistenceUnitFormatProps(persistenceUnit) {
113
+ // Same as Format "DefaultRealU" in Formats ecschema
114
+ return {
115
+ formatTraits: ["keepSingleZero", "keepDecimalPoint", "showUnitLabel"],
116
+ precision: 6,
117
+ type: "Decimal",
118
+ uomSeparator: " ",
119
+ decimalSeparator: ".",
120
+ composite: {
121
+ units: [
122
+ {
123
+ name: persistenceUnit.fullName,
124
+ label: persistenceUnit.label,
125
+ },
126
+ ],
127
+ },
128
+ };
129
+ }
130
+ function getUnitSystemGroupNames(unitSystem) {
131
+ switch (unitSystem) {
132
+ case "imperial":
133
+ return ["IMPERIAL", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
134
+ case "metric":
135
+ return ["SI", "METRIC", "INTERNATIONAL", "FINANCE"];
136
+ case "usCustomary":
137
+ return ["USCUSTOM", "INTERNATIONAL", "FINANCE"];
138
+ case "usSurvey":
139
+ return ["USSURVEY", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
140
+ }
141
+ return [];
142
+ }
143
+ //# sourceMappingURL=Formatting.js.map
@@ -0,0 +1 @@
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,EAAgC,MAAM,sBAAsB,CAAC;AAC1H,OAAO,EAIL,cAAc,EAEd,SAAS,EACT,eAAe,EACf,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAA4B,kBAAkB,EAAuB,MAAM,4BAA4B,CAAC;AA0B5I;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,IAAI,0BAA0B,CAAC,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;AAED,SAAS,6BAA6B,CAAC,eAAoC;IACzE,oDAAoD;IACpD,OAAO;QACL,YAAY,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,CAAC;QACrE,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,GAAG;QACjB,gBAAgB,EAAE,GAAG;QACrB,SAAS,EAAE;YACT,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,eAAe,CAAC,QAAQ;oBAC9B,KAAK,EAAE,eAAe,CAAC,KAAK;iBAC7B;aACF;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,UAA0B;IACzD,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,UAAU;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 { FormatProps, FormatterSpec, Format as QuantityFormat, UnitsProvider, UnitSystemKey } from \"@itwin/core-quantity\";\nimport {\n Format,\n InvertedUnit,\n KindOfQuantity,\n OverrideFormat,\n SchemaContext,\n SchemaKey,\n SchemaMatchType,\n SchemaUnitProvider,\n Unit,\n} from \"@itwin/ecschema-metadata\";\nimport { createDefaultValueFormatter, IPrimitiveValueFormatter, parseFullClassName, TypedPrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Props for `createValueFormatter` function.\n */\ninterface CreateValueFormatterProps {\n /**\n * An instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/) for\n * getting units information.\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-hierarchies` 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 { SchemaContext } from \"@itwin/ecschema-metadata\";\n * import { createValueFormatter } from \"@itwin/presentation-core-interop\";\n *\n * const schemaContext = new SchemaContext();\n * const formatter = createValueFormatter({ schemaContext, unitSystem: \"metric\" });\n * const formattedValue = await formatter({ type: \"Double\", value: 1.234, koqName: \"MySchema.LengthKindOfQuantity\" });\n * ```\n *\n * @beta\n */\nexport function createValueFormatter(props: CreateValueFormatterProps): IPrimitiveValueFormatter {\n const { schemaContext, unitSystem } = props;\n const baseFormatter = props.baseFormatter ?? /* istanbul ignore next */ 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<KindOfQuantity>(koqName);\n if (!koq) {\n throw new Error(`Invalid kind of quantity \"${koqName}\" specified in KoQ full name \"${fullName}\" - it does not exist in schema \"${schemaName}\"`);\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(koq: KindOfQuantity, unitSystem?: UnitSystemKey): Promise<FormattingProps | undefined> {\n const persistenceUnit = await koq.persistenceUnit;\n // istanbul ignore if\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(koq: KindOfQuantity, persistenceUnit: Unit | InvertedUnit, unitSystem?: UnitSystemKey) {\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 unit = format.units && format.units[0][0];\n // istanbul ignore if\n if (!unit) {\n continue;\n }\n const currentUnitSystem = await unit.unitSystem;\n if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {\n return format;\n }\n }\n }\n return undefined;\n}\n\nfunction getFormatProps(format: Format | OverrideFormat): FormatProps {\n return format instanceof OverrideFormat ? format.getFormatProps() : 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: {\n units: [\n {\n name: persistenceUnit.fullName,\n label: persistenceUnit.label,\n },\n ],\n },\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"]}
@@ -0,0 +1,32 @@
1
+ import { LogLevel as CoreLogLevel } from "@itwin/core-bentley";
2
+ import { 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
+ */
7
+ interface ICoreLogger {
8
+ isEnabled(category: string, level: CoreLogLevel): boolean;
9
+ logError(category: string, message: string): void;
10
+ logWarning(category: string, message: string): void;
11
+ logInfo(category: string, message: string): void;
12
+ logTrace(category: string, message: string): void;
13
+ }
14
+ /**
15
+ * Creates a presentation `ILogger` instance that forwards all logging calls to the
16
+ * [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/) API.
17
+ *
18
+ * Usage example:
19
+ *
20
+ * ```ts
21
+ * import { Logger } from "@itwin/core-bentley";
22
+ * import { createLogger } from "@itwin/presentation-core-interop";
23
+ * import { setLogger } from "@itwin/presentation-hierarchies";
24
+ *
25
+ * setLogger(createLogger(Logger));
26
+ * ```
27
+ *
28
+ * @beta
29
+ */
30
+ export declare function createLogger(coreLogger: ICoreLogger): ILogger;
31
+ export {};
32
+ //# sourceMappingURL=Logging.d.ts.map
@@ -0,0 +1 @@
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;AAC/D,OAAO,EAAE,OAAO,EAAY,MAAM,4BAA4B,CAAC;AAE/D;;;GAGG;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"}
@@ -0,0 +1,43 @@
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 { LogLevel as CoreLogLevel } from "@itwin/core-bentley";
6
+ /**
7
+ * Creates a presentation `ILogger` instance that forwards all logging calls to the
8
+ * [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/) API.
9
+ *
10
+ * Usage example:
11
+ *
12
+ * ```ts
13
+ * import { Logger } from "@itwin/core-bentley";
14
+ * import { createLogger } from "@itwin/presentation-core-interop";
15
+ * import { setLogger } from "@itwin/presentation-hierarchies";
16
+ *
17
+ * setLogger(createLogger(Logger));
18
+ * ```
19
+ *
20
+ * @beta
21
+ */
22
+ export function createLogger(coreLogger) {
23
+ return {
24
+ isEnabled: (category, level) => coreLogger.isEnabled(category, getCoreLogLevel(level)),
25
+ logError: (category, msg) => coreLogger.logError(category, msg),
26
+ logWarning: (category, msg) => coreLogger.logWarning(category, msg),
27
+ logInfo: (category, msg) => coreLogger.logInfo(category, msg),
28
+ logTrace: (category, msg) => coreLogger.logTrace(category, msg),
29
+ };
30
+ }
31
+ function getCoreLogLevel(level) {
32
+ switch (level) {
33
+ case "error":
34
+ return CoreLogLevel.Error;
35
+ case "warning":
36
+ return CoreLogLevel.Warning;
37
+ case "info":
38
+ return CoreLogLevel.Info;
39
+ case "trace":
40
+ return CoreLogLevel.Trace;
41
+ }
42
+ }
43
+ //# sourceMappingURL=Logging.js.map
@@ -0,0 +1 @@
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;AAe/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\";\nimport { 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 */\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 * @beta\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"]}
@@ -0,0 +1,28 @@
1
+ import { Schema as CoreSchema, SchemaKey as CoreSchemaKey } from "@itwin/ecschema-metadata";
2
+ import { ECSchemaProvider } from "@itwin/presentation-shared";
3
+ /**
4
+ * Defines input for `createECSchemaProvider`. Generally, this is an instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/)
5
+ * class from `@itwin/ecschema-metadata` package.
6
+ */
7
+ interface CoreSchemaContext {
8
+ getSchema(key: CoreSchemaKey): Promise<CoreSchema | undefined>;
9
+ }
10
+ /**
11
+ * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).
12
+ *
13
+ * Usage example:
14
+ *
15
+ * ```ts
16
+ * import { SchemaContext } from "@itwin/ecschema-metadata";
17
+ * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
18
+ *
19
+ * const schemaContext = new SchemaContext();
20
+ * const schemaProvider = createECSchemaProvider(schemas);
21
+ * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
22
+ * ```
23
+ *
24
+ * @beta
25
+ */
26
+ export declare function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider;
27
+ export {};
28
+ //# sourceMappingURL=Metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Metadata.d.ts","sourceRoot":"","sources":["../../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;;GAGG;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,CAsBzF"}
@@ -0,0 +1,47 @@
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";
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 { SchemaContext } from "@itwin/ecschema-metadata";
14
+ * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
15
+ *
16
+ * const schemaContext = new SchemaContext();
17
+ * const schemaProvider = createECSchemaProvider(schemas);
18
+ * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
19
+ * ```
20
+ *
21
+ * @beta
22
+ */
23
+ export function createECSchemaProvider(schemaContext) {
24
+ async function getSchemaUnprotected(schemaName) {
25
+ const coreSchema = await schemaContext.getSchema(new CoreSchemaKey(schemaName));
26
+ return coreSchema ? createECSchema(coreSchema) : undefined;
27
+ }
28
+ async function getSchemaProtected(schemaName, handledExistingSchemaErrors) {
29
+ // workaround for https://github.com/iTwin/itwinjs-core/issues/6542
30
+ try {
31
+ return await getSchemaUnprotected(schemaName);
32
+ }
33
+ catch (e) {
34
+ if (e instanceof Error && e.message.includes("already exists within this cache") && !handledExistingSchemaErrors.has(schemaName)) {
35
+ handledExistingSchemaErrors.add(schemaName);
36
+ return getSchemaProtected(schemaName, handledExistingSchemaErrors);
37
+ }
38
+ throw e;
39
+ }
40
+ }
41
+ return {
42
+ async getSchema(name) {
43
+ return getSchemaProtected(name, new Set());
44
+ },
45
+ };
46
+ }
47
+ //# sourceMappingURL=Metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAwB,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE5F,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAUpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAgC;IACrE,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,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjI,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC5C,OAAO,kBAAkB,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;YACrE,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK,CAAC,SAAS,CAAC,IAAI;YAClB,OAAO,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAC7C,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 { Schema as CoreSchema, SchemaKey as CoreSchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ECSchemaProvider } from \"@itwin/presentation-shared\";\nimport { createECSchema } from \"./MetadataInternal\";\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 */\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 { SchemaContext } from \"@itwin/ecschema-metadata\";\n * import { createECSchemaProvider } from \"@itwin/presentation-core-interop\";\n *\n * const schemaContext = new SchemaContext();\n * const schemaProvider = createECSchemaProvider(schemas);\n * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages\n * ```\n *\n * @beta\n */\nexport function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider {\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 if (e instanceof Error && e.message.includes(\"already exists within this cache\") && !handledExistingSchemaErrors.has(schemaName)) {\n handledExistingSchemaErrors.add(schemaName);\n return getSchemaProtected(schemaName, handledExistingSchemaErrors);\n }\n throw e;\n }\n }\n return {\n async getSchema(name) {\n return getSchemaProtected(name, new Set());\n },\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { ECClass as CoreClass, Property as CoreProperty, Schema as CoreSchema } from "@itwin/ecschema-metadata";
2
+ import { EC } from "@itwin/presentation-shared";
3
+ /** @internal */
4
+ export declare function createECSchema(schema: CoreSchema): EC.Schema;
5
+ /** @internal */
6
+ export declare function createECClass(coreClass: CoreClass, schema?: EC.Schema): EC.Class;
7
+ /** @internal */
8
+ export declare function createECProperty(coreProperty: CoreProperty, ecClass: EC.Class): EC.Property;
9
+ //# sourceMappingURL=MetadataInternal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetadataInternal.d.ts","sourceRoot":"","sources":["../../../src/core-interop/MetadataInternal.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,OAAO,IAAI,SAAS,EAUpB,QAAQ,IAAI,YAAY,EAGxB,MAAM,IAAI,UAAU,EASrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAEhD,gBAAgB;AAChB,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,EAAE,CAAC,MAAM,CAQ5D;AAwBD,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,CAYhF;AAoFD,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,QAAQ,CAqB3F"}