@itwin/presentation-core-interop 2.0.0-alpha.1 → 2.0.0-alpha.3

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 (83) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/lib/core-interop/Formatting.d.ts.map +1 -0
  3. package/lib/core-interop/Formatting.js.map +1 -0
  4. package/lib/core-interop/IModelKey.d.ts.map +1 -0
  5. package/lib/core-interop/IModelKey.js.map +1 -0
  6. package/lib/core-interop/Logging.d.ts.map +1 -0
  7. package/lib/core-interop/Logging.js.map +1 -0
  8. package/lib/core-interop/Metadata.d.ts.map +1 -0
  9. package/lib/core-interop/Metadata.js.map +1 -0
  10. package/lib/core-interop/MetadataInternal.d.ts.map +1 -0
  11. package/lib/{esm/core-interop → core-interop}/MetadataInternal.js +28 -3
  12. package/lib/core-interop/MetadataInternal.js.map +1 -0
  13. package/lib/{cjs/core-interop → core-interop}/QueryExecutor.d.ts +3 -2
  14. package/lib/core-interop/QueryExecutor.d.ts.map +1 -0
  15. package/lib/{esm/core-interop → core-interop}/QueryExecutor.js +56 -19
  16. package/lib/core-interop/QueryExecutor.js.map +1 -0
  17. package/lib/core-interop/Transactions.d.ts.map +1 -0
  18. package/lib/core-interop/Transactions.js.map +1 -0
  19. package/lib/presentation-core-interop.d.ts.map +1 -0
  20. package/lib/presentation-core-interop.js.map +1 -0
  21. package/package.json +20 -22
  22. package/lib/cjs/core-interop/Formatting.d.ts.map +0 -1
  23. package/lib/cjs/core-interop/Formatting.js +0 -136
  24. package/lib/cjs/core-interop/Formatting.js.map +0 -1
  25. package/lib/cjs/core-interop/IModelKey.d.ts.map +0 -1
  26. package/lib/cjs/core-interop/IModelKey.js +0 -36
  27. package/lib/cjs/core-interop/IModelKey.js.map +0 -1
  28. package/lib/cjs/core-interop/Logging.d.ts.map +0 -1
  29. package/lib/cjs/core-interop/Logging.js +0 -46
  30. package/lib/cjs/core-interop/Logging.js.map +0 -1
  31. package/lib/cjs/core-interop/Metadata.d.ts.map +0 -1
  32. package/lib/cjs/core-interop/Metadata.js +0 -62
  33. package/lib/cjs/core-interop/Metadata.js.map +0 -1
  34. package/lib/cjs/core-interop/MetadataInternal.d.ts.map +0 -1
  35. package/lib/cjs/core-interop/MetadataInternal.js +0 -404
  36. package/lib/cjs/core-interop/MetadataInternal.js.map +0 -1
  37. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +0 -1
  38. package/lib/cjs/core-interop/QueryExecutor.js +0 -112
  39. package/lib/cjs/core-interop/QueryExecutor.js.map +0 -1
  40. package/lib/cjs/core-interop/Transactions.d.ts.map +0 -1
  41. package/lib/cjs/core-interop/Transactions.js +0 -60
  42. package/lib/cjs/core-interop/Transactions.js.map +0 -1
  43. package/lib/cjs/package.json +0 -1
  44. package/lib/cjs/presentation-core-interop.d.ts.map +0 -1
  45. package/lib/cjs/presentation-core-interop.js +0 -20
  46. package/lib/cjs/presentation-core-interop.js.map +0 -1
  47. package/lib/esm/core-interop/Formatting.d.ts +0 -45
  48. package/lib/esm/core-interop/Formatting.d.ts.map +0 -1
  49. package/lib/esm/core-interop/Formatting.js.map +0 -1
  50. package/lib/esm/core-interop/IModelKey.d.ts +0 -31
  51. package/lib/esm/core-interop/IModelKey.d.ts.map +0 -1
  52. package/lib/esm/core-interop/IModelKey.js.map +0 -1
  53. package/lib/esm/core-interop/Logging.d.ts +0 -33
  54. package/lib/esm/core-interop/Logging.d.ts.map +0 -1
  55. package/lib/esm/core-interop/Logging.js.map +0 -1
  56. package/lib/esm/core-interop/Metadata.d.ts +0 -30
  57. package/lib/esm/core-interop/Metadata.d.ts.map +0 -1
  58. package/lib/esm/core-interop/Metadata.js.map +0 -1
  59. package/lib/esm/core-interop/MetadataInternal.d.ts +0 -10
  60. package/lib/esm/core-interop/MetadataInternal.d.ts.map +0 -1
  61. package/lib/esm/core-interop/MetadataInternal.js.map +0 -1
  62. package/lib/esm/core-interop/QueryExecutor.d.ts +0 -33
  63. package/lib/esm/core-interop/QueryExecutor.d.ts.map +0 -1
  64. package/lib/esm/core-interop/QueryExecutor.js.map +0 -1
  65. package/lib/esm/core-interop/Transactions.d.ts +0 -71
  66. package/lib/esm/core-interop/Transactions.d.ts.map +0 -1
  67. package/lib/esm/core-interop/Transactions.js.map +0 -1
  68. package/lib/esm/presentation-core-interop.d.ts +0 -7
  69. package/lib/esm/presentation-core-interop.d.ts.map +0 -1
  70. package/lib/esm/presentation-core-interop.js.map +0 -1
  71. /package/lib/{cjs/core-interop → core-interop}/Formatting.d.ts +0 -0
  72. /package/lib/{esm/core-interop → core-interop}/Formatting.js +0 -0
  73. /package/lib/{cjs/core-interop → core-interop}/IModelKey.d.ts +0 -0
  74. /package/lib/{esm/core-interop → core-interop}/IModelKey.js +0 -0
  75. /package/lib/{cjs/core-interop → core-interop}/Logging.d.ts +0 -0
  76. /package/lib/{esm/core-interop → core-interop}/Logging.js +0 -0
  77. /package/lib/{cjs/core-interop → core-interop}/Metadata.d.ts +0 -0
  78. /package/lib/{esm/core-interop → core-interop}/Metadata.js +0 -0
  79. /package/lib/{cjs/core-interop → core-interop}/MetadataInternal.d.ts +0 -0
  80. /package/lib/{cjs/core-interop → core-interop}/Transactions.d.ts +0 -0
  81. /package/lib/{esm/core-interop → core-interop}/Transactions.js +0 -0
  82. /package/lib/{cjs/presentation-core-interop.d.ts → presentation-core-interop.d.ts} +0 -0
  83. /package/lib/{esm/presentation-core-interop.js → presentation-core-interop.js} +0 -0
@@ -1,136 +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.createValueFormatter = createValueFormatter;
8
- const core_quantity_1 = require("@itwin/core-quantity");
9
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
10
- const presentation_shared_1 = require("@itwin/presentation-shared");
11
- /**
12
- * Creates an instance of `IPrimitiveValueFormatter` that knows how to format values of properties with assigned kind of quantity. In
13
- * case the property does not have an assigned kind of quantity, the base formatter is used.
14
- *
15
- * Usage example:
16
- *
17
- * ```ts
18
- * import { IModelConnection } from "@itwin/core-frontend";
19
- * import { createValueFormatter } from "@itwin/presentation-core-interop";
20
- *
21
- * const imodel: IModelConnection = getIModel();
22
- * const formatter = createValueFormatter({ schemaContext: imodel.schemaContext, unitSystem: "metric" });
23
- * const formattedValue = await formatter({ type: "Double", value: 1.234, koqName: "MySchema.LengthKindOfQuantity" });
24
- * ```
25
- *
26
- * @public
27
- */
28
- function createValueFormatter(props) {
29
- const { schemaContext, unitSystem } = props;
30
- /* v8 ignore next -- @preserve */
31
- const baseFormatter = props.baseFormatter ?? (0, presentation_shared_1.createDefaultValueFormatter)();
32
- const unitsProvider = new ecschema_metadata_1.SchemaUnitProvider(schemaContext);
33
- return async function (value) {
34
- if (value.type === "Double" && !!value.koqName) {
35
- const koq = await getKindOfQuantity(schemaContext, value.koqName);
36
- const spec = await getFormatterSpec(unitsProvider, koq, unitSystem);
37
- if (spec) {
38
- return spec.applyFormatting(value.value);
39
- }
40
- }
41
- return baseFormatter(value);
42
- };
43
- }
44
- async function getKindOfQuantity(schemas, fullName) {
45
- const { schemaName, className: koqName } = (0, presentation_shared_1.parseFullClassName)(fullName);
46
- const schema = await schemas.getSchema(new ecschema_metadata_1.SchemaKey(schemaName), ecschema_metadata_1.SchemaMatchType.Latest);
47
- if (!schema) {
48
- throw new Error(`Invalid schema "${schemaName}" specified in KoQ full name "${fullName}"`);
49
- }
50
- const koq = await schema.getItem(koqName, ecschema_metadata_1.KindOfQuantity);
51
- if (!koq) {
52
- throw new Error(`Invalid kind of quantity "${koqName}" specified in KoQ full name "${fullName}" - it does not exist in schema "${schemaName}"`);
53
- }
54
- return koq;
55
- }
56
- async function getFormatterSpec(unitsProvider, koq, unitSystem) {
57
- const formattingProps = await getFormattingProps(koq, unitSystem);
58
- if (!formattingProps) {
59
- return undefined;
60
- }
61
- const { formatProps, persistenceUnitName } = formattingProps;
62
- const persistenceUnit = await unitsProvider.findUnitByName(persistenceUnitName);
63
- const format = await core_quantity_1.Format.createFromJSON("", unitsProvider, formatProps);
64
- return core_quantity_1.FormatterSpec.create("", format, unitsProvider, persistenceUnit);
65
- }
66
- async function getFormattingProps(koq, unitSystem) {
67
- const persistenceUnit = await koq.persistenceUnit;
68
- if (!persistenceUnit) {
69
- return undefined;
70
- }
71
- const formatProps = await getKoqFormatProps(koq, persistenceUnit, unitSystem);
72
- if (!formatProps) {
73
- return undefined;
74
- }
75
- return { formatProps, persistenceUnitName: persistenceUnit.fullName };
76
- }
77
- async function getKoqFormatProps(koq, persistenceUnit, unitSystem) {
78
- const unitSystems = getUnitSystemGroupNames(unitSystem);
79
- // use one of KOQ presentation format that matches requested unit system
80
- const presentationFormat = await getKoqPresentationFormat(koq, unitSystems);
81
- if (presentationFormat) {
82
- return getFormatProps(presentationFormat);
83
- }
84
- // use persistence unit format if it matches requested unit system and matching presentation format was not found
85
- const persistenceUnitSystem = await persistenceUnit.unitSystem;
86
- if (persistenceUnitSystem && unitSystems.includes(persistenceUnitSystem.name.toUpperCase())) {
87
- return getPersistenceUnitFormatProps(persistenceUnit);
88
- }
89
- // use default presentation format if persistence unit does not match requested unit system
90
- if (koq.defaultPresentationFormat) {
91
- return getFormatProps(koq.defaultPresentationFormat);
92
- }
93
- return undefined;
94
- }
95
- async function getKoqPresentationFormat(koq, unitSystems) {
96
- const presentationFormats = koq.presentationFormats;
97
- for (const system of unitSystems) {
98
- for (const format of presentationFormats) {
99
- const units = format instanceof ecschema_metadata_1.OverrideFormat ? format.units : (await format).units;
100
- const lazyUnit = units && units[0][0];
101
- const currentUnitSystem = lazyUnit && (await lazyUnit).unitSystem;
102
- if (currentUnitSystem && currentUnitSystem.name.toUpperCase() === system) {
103
- return format;
104
- }
105
- }
106
- }
107
- return undefined;
108
- }
109
- async function getFormatProps(format) {
110
- return format instanceof ecschema_metadata_1.OverrideFormat ? format.getFormatProps() : (await 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: { units: [{ name: persistenceUnit.fullName, label: persistenceUnit.label }] },
121
- };
122
- }
123
- function getUnitSystemGroupNames(unitSystem) {
124
- switch (unitSystem) {
125
- case "imperial":
126
- return ["IMPERIAL", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
127
- case "metric":
128
- return ["SI", "METRIC", "INTERNATIONAL", "FINANCE"];
129
- case "usCustomary":
130
- return ["USCUSTOM", "INTERNATIONAL", "FINANCE"];
131
- case "usSurvey":
132
- return ["USSURVEY", "USCUSTOM", "INTERNATIONAL", "FINANCE"];
133
- }
134
- return [];
135
- }
136
- //# sourceMappingURL=Formatting.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Formatting.js","sourceRoot":"","sources":["../../../src/core-interop/Formatting.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AA0DhG,oDAeC;AAvED,wDAA+E;AAC/E,gEAMkC;AAClC,oEAA6F;AA+B7F;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,oBAAoB,CAAC,KAAgC;IACnE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC5C,iCAAiC;IACjC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,IAAI,IAAA,iDAA2B,GAAE,CAAC;IAC3E,MAAM,aAAa,GAAG,IAAI,sCAAkB,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,GA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Ae,CAAC;QACrE,SAAS,EAAE,CAAC;QACZ,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,GAAG;QACjB,gBAAgB,EAAE,GAAG;QACrB,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,CAAC,EAAE;KACzF,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 { 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 +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,36 +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.createIModelKey = createIModelKey;
8
- /**
9
- * 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
10
- * set (e.g. when using [BlankConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/blankconnection/)) - `name` property
11
- * is used instead. Finally, if both are empty - the function will throw an error.
12
- *
13
- * Example:
14
- *
15
- * ```ts
16
- * import { IModelConnection } from "@itwin/core-frontend";
17
- * import { createIModelKey } from "@itwin/presentation-core-interop";
18
- *
19
- * IModelConnection.onOpen.addListener((imodel: IModelConnection) => {
20
- * const key = createIModelKey(imodel);
21
- * console.log(`IModel opened: "${key}"`);
22
- * });
23
- * ```
24
- *
25
- * @public
26
- */
27
- function createIModelKey(imodel) {
28
- if (imodel.key.length) {
29
- return imodel.key;
30
- }
31
- if (imodel.name.length) {
32
- return imodel.name;
33
- }
34
- throw new Error(`Provided iModel doesn't have a key or name.`);
35
- }
36
- //# sourceMappingURL=IModelKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IModelKey.js","sourceRoot":"","sources":["../../../src/core-interop/IModelKey.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AA+BhG,0CAQC;AA3BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,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 +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,46 +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.createLogger = createLogger;
8
- const core_bentley_1 = require("@itwin/core-bentley");
9
- /**
10
- * Creates a presentation `ILogger` instance that forwards all logging calls to the
11
- * [Logger](https://www.itwinjs.org/reference/core-bentley/logging/logger/) API.
12
- *
13
- * Usage example:
14
- *
15
- * ```ts
16
- * import { Logger } from "@itwin/core-bentley";
17
- * import { createLogger } from "@itwin/presentation-core-interop";
18
- * import { setLogger } from "@itwin/presentation-hierarchies";
19
- *
20
- * setLogger(createLogger(Logger));
21
- * ```
22
- *
23
- * @public
24
- */
25
- function createLogger(coreLogger) {
26
- return {
27
- isEnabled: (category, level) => coreLogger.isEnabled(category, getCoreLogLevel(level)),
28
- logError: (category, msg) => coreLogger.logError(category, msg),
29
- logWarning: (category, msg) => coreLogger.logWarning(category, msg),
30
- logInfo: (category, msg) => coreLogger.logInfo(category, msg),
31
- logTrace: (category, msg) => coreLogger.logTrace(category, msg),
32
- };
33
- }
34
- function getCoreLogLevel(level) {
35
- switch (level) {
36
- case "error":
37
- return core_bentley_1.LogLevel.Error;
38
- case "warning":
39
- return core_bentley_1.LogLevel.Warning;
40
- case "info":
41
- return core_bentley_1.LogLevel.Info;
42
- case "trace":
43
- return core_bentley_1.LogLevel.Trace;
44
- }
45
- }
46
- //# sourceMappingURL=Logging.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logging.js","sourceRoot":"","sources":["../../../src/core-interop/Logging.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAmChG,oCAQC;AAzCD,sDAA+D;AAiB/D;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,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,uBAAY,CAAC,KAAK,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,uBAAY,CAAC,OAAO,CAAC;QAC9B,KAAK,MAAM;YACT,OAAO,uBAAY,CAAC,IAAI,CAAC;QAC3B,KAAK,OAAO;YACV,OAAO,uBAAY,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 +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,62 +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.createECSchemaProvider = createECSchemaProvider;
8
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
- const MetadataInternal_js_1 = require("./MetadataInternal.js");
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 { IModelConnection } from "@itwin/core-frontend";
17
- * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
18
- *
19
- * const imodel: IModelConnection = getIModel();
20
- * const schemaProvider = createECSchemaProvider(imodel.schemaContext);
21
- * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
22
- * ```
23
- *
24
- * @public
25
- */
26
- function createECSchemaProvider(schemaContext) {
27
- const schemaRequestsCache = new Map();
28
- async function getSchemaUnprotected(schemaName) {
29
- const coreSchema = await schemaContext.getSchema(new ecschema_metadata_1.SchemaKey(schemaName));
30
- return coreSchema ? (0, MetadataInternal_js_1.createECSchema)(coreSchema) : undefined;
31
- }
32
- async function getSchemaProtected(schemaName, handledExistingSchemaErrors) {
33
- // workaround for https://github.com/iTwin/itwinjs-core/issues/6542
34
- try {
35
- return await getSchemaUnprotected(schemaName);
36
- }
37
- catch (e) {
38
- /* v8 ignore else -- @preserve */
39
- if (e instanceof Error) {
40
- if (e.message.includes("already exists within this cache") && !handledExistingSchemaErrors.has(schemaName)) {
41
- handledExistingSchemaErrors.add(schemaName);
42
- return getSchemaProtected(schemaName, handledExistingSchemaErrors);
43
- }
44
- if (e.message.includes("schema not found")) {
45
- return undefined;
46
- }
47
- }
48
- throw e;
49
- }
50
- }
51
- return {
52
- async getSchema(name) {
53
- let promise = schemaRequestsCache.get(name);
54
- if (!promise) {
55
- promise = getSchemaProtected(name, new Set());
56
- schemaRequestsCache.set(name, promise);
57
- }
58
- return promise;
59
- },
60
- };
61
- }
62
- //# sourceMappingURL=Metadata.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/core-interop/Metadata.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAiChG,wDAkCC;AAjED,gEAAsE;AACtE,+DAAuD;AAcvD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,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,6BAAa,CAAC,UAAU,CAAC,CAAC,CAAC;QAChF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAA,oCAAc,EAAC,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 +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,EAGxB,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,CAW5D;AAwBD,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,CAYhF;AAoGD,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,QAAQ,CAqB3F"}