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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
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
+ {"version":3,"file":"Metadata.d.ts","sourceRoot":"","sources":["../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,gBAAgB,EAA0B,MAAM,4BAA4B,CAAC;AAEpG,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;;;GAKG;AACH,KAAK,oBAAoB,GAAG,IAAI,CAC9B,cAAc,EACZ,aAAa,GACb,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,WAAW,GACX,kBAAkB,GAClB,YAAY,GACZ,WAAW,GACX,iBAAiB,GACjB,oBAAoB,GACpB,sBAAsB,CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,KAAK,oBAAoB,GAAG,CAAC,KAAK,CAAC,EAAE;IAAE,OAAO,CAAC,EAA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,wBAAwB,EACjD,0BAA0B,EAAE,EAAE,CAAC,wBAAwB,GACtD,OAAO,CAAC;IACX,+DAA+D;IAC/D,oBAAoB,CAClB,aAAa,EAAE,EAAE,CAAC,wBAAwB,EAC1C,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GACjC,EAAE,CAAC,wBAAwB,EAAE,CAAC;CAClC;AAED,gBAAgB;AAChB,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAgEnC"}
@@ -2,10 +2,31 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { SchemaKey as CoreSchemaKey } from "@itwin/ecschema-metadata";
6
- import { createECSchema } from "./MetadataInternal.js";
5
+ import { bufferTime, filter, firstValueFrom, map, mergeMap, share, Subject } from "rxjs";
6
+ import { SchemaViewPrimitiveType, StrengthDirection } from "@itwin/ecschema-metadata";
7
+ import { normalizeFullClassName } from "@itwin/presentation-shared";
7
8
  /**
8
- * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).
9
+ * Accumulates schema names requested within the same frame and issues a single `getSchemaView` request for all of
10
+ * them in the next one, returning each caller the batch's result. Used both by `createECSchemaProvider` and by
11
+ * `createValueFormatter` (which resolves kind of quantity persistence units without needing the class hierarchy).
12
+ *
13
+ * @internal
14
+ */
15
+ export function createBatchedSchemaViewGetter(imodel) {
16
+ const schemaNameSubject = new Subject();
17
+ const schemaViewBatches = schemaNameSubject.pipe(bufferTime(0), filter((schemaNames) => schemaNames.length > 0), mergeMap(async (schemaNames) => {
18
+ const schemas = new Set(schemaNames);
19
+ return { schemas, schemaView: await imodel.getSchemaView({ schemas: [...schemas] }) };
20
+ }), share());
21
+ return async function getSchemaView(schemaName) {
22
+ const schemaView = firstValueFrom(schemaViewBatches.pipe(filter((batch) => batch.schemas.has(schemaName)), map((batch) => batch.schemaView)));
23
+ schemaNameSubject.next(schemaName);
24
+ return schemaView;
25
+ };
26
+ }
27
+ /**
28
+ * Creates an `ECSchemaProvider` for a given iModel with [SchemaView](https://www.itwinjs.org/reference/ecschema-metadata/context/schemaview/)
29
+ * getter and query reader factory.
9
30
  *
10
31
  * Usage example:
11
32
  *
@@ -14,46 +35,474 @@ import { createECSchema } from "./MetadataInternal.js";
14
35
  * import { createECSchemaProvider } from "@itwin/presentation-core-interop";
15
36
  *
16
37
  * const imodel: IModelConnection = getIModel();
17
- * const schemaProvider = createECSchemaProvider(imodel.schemaContext);
38
+ * const schemaProvider = createECSchemaProvider(imodel);
18
39
  * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages
19
40
  * ```
20
41
  *
21
42
  * @public
22
43
  */
23
- export function createECSchemaProvider(schemaContext) {
24
- const schemaRequestsCache = new Map();
25
- async function getSchemaUnprotected(schemaName) {
26
- const coreSchema = await schemaContext.getSchema(new CoreSchemaKey(schemaName));
27
- return coreSchema ? createECSchema(coreSchema) : undefined;
28
- }
29
- async function getSchemaProtected(schemaName, handledExistingSchemaErrors) {
30
- // workaround for https://github.com/iTwin/itwinjs-core/issues/6542
31
- try {
32
- return await getSchemaUnprotected(schemaName);
44
+ export function createECSchemaProvider(imodel) {
45
+ const getSchemaView = createBatchedSchemaViewGetter(imodel);
46
+ // Ensures we only create a single `ECClassHierarchyResolver` for the iModel, which is used to resolve derived classes for all schemas.
47
+ // Cache the promise (not the resolved value) so concurrent `getSchema` calls share one `createECClassHierarchyResolver` invocation.
48
+ let cachedClassHierarchyResolverPromise;
49
+ // Set once the resolver promise settles. Allows `classDerivesFrom` to answer synchronously after the hierarchy is loaded.
50
+ let cachedClassHierarchyResolver;
51
+ function getClassHierarchyResolver() {
52
+ if (cachedClassHierarchyResolver) {
53
+ return cachedClassHierarchyResolver;
33
54
  }
34
- catch (e) {
35
- /* v8 ignore else -- @preserve */
36
- if (e instanceof Error) {
37
- if (e.message.includes("already exists within this cache") && !handledExistingSchemaErrors.has(schemaName)) {
38
- handledExistingSchemaErrors.add(schemaName);
39
- return getSchemaProtected(schemaName, handledExistingSchemaErrors);
40
- }
41
- if (e.message.includes("schema not found")) {
42
- return undefined;
43
- }
55
+ cachedClassHierarchyResolverPromise ??= createECClassHierarchyResolver(imodel).then((resolver) => {
56
+ cachedClassHierarchyResolver = resolver;
57
+ return resolver;
58
+ });
59
+ return cachedClassHierarchyResolverPromise;
60
+ }
61
+ async function getSchemaProviderContext(schemaName) {
62
+ const [classHierarchyResolver, schemaView] = await Promise.all([
63
+ getClassHierarchyResolver(),
64
+ getSchemaView(schemaName),
65
+ ]);
66
+ return { classHierarchyResolver, schemaView };
67
+ }
68
+ // Cache the resolved schema by name so repeated `getSchema`/`getClass` calls reuse it instead of issuing a new
69
+ // `getSchemaView` request each time. The cached promise doubles as an in-flight guard: concurrent
70
+ // first-time requests for the same schema share it (and its underlying `getSchemaView` request) instead of each
71
+ // building the schema. The entry is retained until the schema view it was built from is marked outdated by the host
72
+ // (a newer view has replaced it), at which point the next access refreshes it.
73
+ const schemaCache = new Map();
74
+ async function fetchSchema(name) {
75
+ // Cache built `EC.Class` objects (by full name) for this schema, so repeated accesses (e.g. the
76
+ // `EC.Property.class` getter, invoked once per grouped node) reuse a single class instead of rebuilding it from
77
+ // the schema view every time. Scoped to the fetch so a later refetch (when the view is outdated) starts fresh.
78
+ const classCache = new Map();
79
+ const entry = (async () => {
80
+ const { classHierarchyResolver, schemaView } = await getSchemaProviderContext(name);
81
+ const svSchema = schemaView.getSchema(name);
82
+ const schema = svSchema
83
+ ? createECSchemaFromSchemaView(svSchema, { schemaView, classHierarchyResolver, classCache })
84
+ : undefined;
85
+ return { schemaView, schema };
86
+ })();
87
+ schemaCache.set(name, entry);
88
+ // Drop rejected entries so a transient failure doesn't get cached permanently.
89
+ /* v8 ignore next 4 -- defensive cleanup for rejected cache entries while a newer entry may have already replaced this one */
90
+ entry.catch(() => {
91
+ if (schemaCache.get(name) === entry) {
92
+ schemaCache.delete(name);
44
93
  }
45
- throw e;
46
- }
94
+ });
95
+ return entry;
47
96
  }
48
97
  return {
49
98
  async getSchema(name) {
50
- let promise = schemaRequestsCache.get(name);
51
- if (!promise) {
52
- promise = getSchemaProtected(name, new Set());
53
- schemaRequestsCache.set(name, promise);
99
+ const cached = schemaCache.get(name);
100
+ const entry = await (cached ?? fetchSchema(name));
101
+ return entry.schemaView.isOutdated ? (await fetchSchema(name)).schema : entry.schema;
102
+ },
103
+ classDerivesFrom(derivedClassFullName, candidateBaseClassFullName) {
104
+ // A class always derives from itself. This matches the semantics of the deprecated `ECClassHierarchyInspector`.
105
+ if (derivedClassFullName === candidateBaseClassFullName) {
106
+ return true;
107
+ }
108
+ const resolver = getClassHierarchyResolver();
109
+ return resolver instanceof Promise
110
+ ? resolver.then((r) => r.classDerivesFrom(derivedClassFullName, candidateBaseClassFullName))
111
+ : resolver.classDerivesFrom(derivedClassFullName, candidateBaseClassFullName);
112
+ },
113
+ };
114
+ }
115
+ export function createECSchemaFromSchemaView(svSchema, context) {
116
+ const ecSchema = {
117
+ name: svSchema.name,
118
+ description: svSchema.description,
119
+ version: { read: svSchema.readVersion, write: svSchema.writeVersion, minor: svSchema.minorVersion },
120
+ isHidden: svSchema.isHidden,
121
+ getClass(name) {
122
+ const svClass = svSchema.getClass(name);
123
+ return svClass ? getECClassFromSchemaView(svClass, { ...context, schema: ecSchema }) : undefined;
124
+ },
125
+ getEnumeration(name) {
126
+ const svEnum = svSchema.getEnumeration(name);
127
+ return svEnum ? createECEnumerationFromSchemaView(svEnum, ecSchema) : undefined;
128
+ },
129
+ getKindOfQuantity(name) {
130
+ const svKoq = svSchema.getKindOfQuantity(name);
131
+ return svKoq ? createECKoqFromSchemaView(svKoq, ecSchema) : undefined;
132
+ },
133
+ getPropertyCategory(name) {
134
+ const svCategory = svSchema.getPropertyCategory(name);
135
+ return svCategory ? createECPropertyCategoryFromSchemaView(svCategory, ecSchema) : undefined;
136
+ },
137
+ };
138
+ return ecSchema;
139
+ }
140
+ /**
141
+ * Cache-aware entry point for building an `EC.Class` from a schema view class: returns a previously built class for
142
+ * the same full name, otherwise builds one via `createECClassFromSchemaView` and stores it in the context's cache.
143
+ */
144
+ function getECClassFromSchemaView(svClass, context) {
145
+ // Key by the schema view's raw full name: it is a stable identifier for the class, so we avoid normalizing it on
146
+ // every (hot) cache hit. `createECClassFromSchemaView` normalizes once, on a miss, for the `EC.Class.fullName` field.
147
+ const cached = context.classCache.get(svClass.fullName);
148
+ if (cached) {
149
+ return cached;
150
+ }
151
+ const ecClass = createECClassFromSchemaView(svClass, context);
152
+ context.classCache.set(svClass.fullName, ecClass);
153
+ return ecClass;
154
+ }
155
+ export function createECClassFromSchemaView(svClass, context) {
156
+ const { classHierarchyResolver, schema } = context;
157
+ const fullName = normalizeFullClassName(svClass.fullName);
158
+ const ecClass = {
159
+ schema,
160
+ fullName,
161
+ name: svClass.name,
162
+ label: svClass.label,
163
+ description: svClass.description,
164
+ isHidden: svClass.isHidden,
165
+ isEntityClass() {
166
+ return svClass.isEntity();
167
+ },
168
+ isRelationshipClass() {
169
+ return svClass.isRelationship();
170
+ },
171
+ isStructClass() {
172
+ return svClass.isStruct();
173
+ },
174
+ isMixin() {
175
+ return svClass.isMixin();
176
+ },
177
+ get baseClass() {
178
+ return svClass.baseClass
179
+ ? getECClassFromSchemaView(svClass.baseClass, {
180
+ ...context,
181
+ schema: useOrCreateSchema(svClass.baseClass.schema, context),
182
+ })
183
+ : undefined;
184
+ },
185
+ is(classOrClassName, schemaName) {
186
+ if (typeof classOrClassName === "string") {
187
+ return svClass.is(`${schemaName}.${classOrClassName}`);
54
188
  }
55
- return promise;
189
+ return svClass.is(classOrClassName.fullName);
190
+ },
191
+ getProperty(name) {
192
+ const svProp = svClass.getProperty(name);
193
+ return svProp ? createECPropertyFromSchemaView(svProp, ecClass, context) : undefined;
194
+ },
195
+ getProperties() {
196
+ return svClass.getProperties().map((p) => createECPropertyFromSchemaView(p, ecClass, context));
56
197
  },
198
+ getOwnProperties() {
199
+ return svClass.getOwnProperties().map((p) => createECPropertyFromSchemaView(p, ecClass, context));
200
+ },
201
+ getDerivedClassNames(props) {
202
+ return classHierarchyResolver.getDerivedClassNames(fullName, props);
203
+ },
204
+ };
205
+ if (svClass.isEntity()) {
206
+ const ecEntity = {
207
+ ...ecClass,
208
+ getMixins() {
209
+ return svClass.mixins.map((m) => getECClassFromSchemaView(m, { ...context, schema: useOrCreateSchema(m.schema, context) }));
210
+ },
211
+ };
212
+ return ecEntity;
213
+ }
214
+ if (svClass.isRelationship()) {
215
+ const ecRel = {
216
+ ...ecClass,
217
+ direction: svClass.strengthDirection === StrengthDirection.Forward ? "Forward" : "Backward",
218
+ source: svClass.source
219
+ ? createECRelConstraintFromSchemaView(svClass.source, context)
220
+ : createEmptyRelConstraint(),
221
+ target: svClass.target
222
+ ? createECRelConstraintFromSchemaView(svClass.target, context)
223
+ : createEmptyRelConstraint(),
224
+ };
225
+ return ecRel;
226
+ }
227
+ return ecClass;
228
+ }
229
+ function useOrCreateSchema(svSchema, context) {
230
+ const { schema: currentSchema, ...schemalessContext } = context;
231
+ if (svSchema.name === currentSchema.name) {
232
+ return currentSchema;
233
+ }
234
+ return createECSchemaFromSchemaView(svSchema, schemalessContext);
235
+ }
236
+ function createEmptyRelConstraint() {
237
+ return {
238
+ multiplicity: { lowerLimit: 0, upperLimit: 0 },
239
+ polymorphic: false,
240
+ constraintClasses: [],
241
+ abstractConstraint: undefined,
57
242
  };
58
243
  }
244
+ function createECRelConstraintFromSchemaView(svConstraint, context) {
245
+ return {
246
+ multiplicity: {
247
+ lowerLimit: svConstraint.multiplicityLower,
248
+ // `SchemaView` reports an unbounded upper limit as `0`.
249
+ upperLimit: svConstraint.multiplicityUpper === 0 ? "unbounded" : svConstraint.multiplicityUpper,
250
+ },
251
+ polymorphic: svConstraint.polymorphic,
252
+ get constraintClasses() {
253
+ return svConstraint.constraintClasses.map((c) => getECClassFromSchemaView(c, { ...context, schema: useOrCreateSchema(c.schema, context) }));
254
+ },
255
+ get abstractConstraint() {
256
+ // `SchemaView` only exposes an explicitly-defined abstract constraint. To match EC semantics (and the
257
+ // standard `RelationshipConstraint` implementation), fall back to the sole constraint class when there's exactly one.
258
+ const svClass = svConstraint.abstractConstraint ??
259
+ (svConstraint.constraintClasses.length === 1 ? svConstraint.constraintClasses[0] : undefined);
260
+ if (!svClass) {
261
+ return undefined;
262
+ }
263
+ return getECClassFromSchemaView(svClass, { ...context, schema: useOrCreateSchema(svClass.schema, context) });
264
+ },
265
+ };
266
+ }
267
+ export function createECPropertyFromSchemaView(svProp, ecClass, context) {
268
+ const base = {
269
+ // `svProp.declaringClass` is the class that declared or contributed this property (a base class for an
270
+ // inherited property, or a mixin for a mixin-contributed one). It's `undefined` only for view properties,
271
+ // in which case we fall back to the class the property was enumerated from.
272
+ get class() {
273
+ return svProp.declaringClass
274
+ ? getECClassFromSchemaView(svProp.declaringClass, {
275
+ ...context,
276
+ schema: useOrCreateSchema(svProp.declaringClass.schema, context),
277
+ })
278
+ : ecClass;
279
+ },
280
+ name: svProp.name,
281
+ description: svProp.description,
282
+ label: svProp.label,
283
+ isHidden: svProp.isHidden,
284
+ get category() {
285
+ return svProp.category
286
+ ? createECPropertyCategoryFromSchemaView(svProp.category, useOrCreateSchema(svProp.category.schema, context))
287
+ : undefined;
288
+ },
289
+ isArray() {
290
+ return svProp.isArray();
291
+ },
292
+ isStruct() {
293
+ return false;
294
+ },
295
+ isPrimitive() {
296
+ return false;
297
+ },
298
+ isEnumeration() {
299
+ return false;
300
+ },
301
+ isNavigation() {
302
+ return false;
303
+ },
304
+ };
305
+ if (svProp.isNavigation()) {
306
+ return {
307
+ ...base,
308
+ isNavigation() {
309
+ return true;
310
+ },
311
+ get direction() {
312
+ return svProp.direction === StrengthDirection.Forward ? "Forward" : "Backward";
313
+ },
314
+ get relationshipClass() {
315
+ return getECClassFromSchemaView(svProp.relationshipClass, {
316
+ ...context,
317
+ schema: useOrCreateSchema(svProp.relationshipClass.schema, context),
318
+ });
319
+ },
320
+ };
321
+ }
322
+ // Check enumeration before primitive (enum is a facet of primitive in CoreSchemaView, but separate in EC)
323
+ if (svProp.isEnumeration()) {
324
+ const arrayFields = svProp.isArray()
325
+ ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }
326
+ : undefined;
327
+ return {
328
+ ...base,
329
+ ...arrayFields,
330
+ isEnumeration() {
331
+ return true;
332
+ },
333
+ isArray() {
334
+ return svProp.isArray();
335
+ },
336
+ get extendedTypeName() {
337
+ return svProp.extendedTypeName;
338
+ },
339
+ get enumeration() {
340
+ return svProp.enumeration
341
+ ? createECEnumerationFromSchemaView(svProp.enumeration, useOrCreateSchema(svProp.enumeration.schema, context))
342
+ : undefined;
343
+ },
344
+ };
345
+ }
346
+ if (svProp.isPrimitive()) {
347
+ const arrayFields = svProp.isArray()
348
+ ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }
349
+ : undefined;
350
+ return {
351
+ ...base,
352
+ ...arrayFields,
353
+ isPrimitive() {
354
+ return true;
355
+ },
356
+ isArray() {
357
+ return svProp.isArray();
358
+ },
359
+ get primitiveType() {
360
+ return mapSchemaViewPrimitiveType(svProp.primitiveType);
361
+ },
362
+ get extendedTypeName() {
363
+ return svProp.extendedTypeName;
364
+ },
365
+ get kindOfQuantity() {
366
+ return svProp.kindOfQuantity
367
+ ? createECKoqFromSchemaView(svProp.kindOfQuantity, useOrCreateSchema(svProp.kindOfQuantity.schema, context))
368
+ : undefined;
369
+ },
370
+ };
371
+ }
372
+ if (svProp.isStruct()) {
373
+ const arrayFields = svProp.isArray()
374
+ ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }
375
+ : undefined;
376
+ return {
377
+ ...base,
378
+ ...arrayFields,
379
+ isStruct() {
380
+ return true;
381
+ },
382
+ isArray() {
383
+ return svProp.isArray();
384
+ },
385
+ get structClass() {
386
+ return getECClassFromSchemaView(svProp.structClass, {
387
+ ...context,
388
+ schema: useOrCreateSchema(svProp.structClass.schema, context),
389
+ });
390
+ },
391
+ };
392
+ }
393
+ throw new Error(`Unexpected property type for ${svProp.declaringClass ? svProp.declaringClass.fullName : "<ECCView>"}.${svProp.name}`);
394
+ }
395
+ function mapSchemaViewPrimitiveType(svType) {
396
+ switch (svType) {
397
+ case SchemaViewPrimitiveType.Binary:
398
+ return "Binary";
399
+ case SchemaViewPrimitiveType.Boolean:
400
+ return "Boolean";
401
+ case SchemaViewPrimitiveType.DateTime:
402
+ return "DateTime";
403
+ case SchemaViewPrimitiveType.Double:
404
+ return "Double";
405
+ case SchemaViewPrimitiveType.IGeometry:
406
+ return "IGeometry";
407
+ case SchemaViewPrimitiveType.Integer:
408
+ return "Integer";
409
+ case SchemaViewPrimitiveType.Long:
410
+ return "Long";
411
+ case SchemaViewPrimitiveType.Point2d:
412
+ return "Point2d";
413
+ case SchemaViewPrimitiveType.Point3d:
414
+ return "Point3d";
415
+ case SchemaViewPrimitiveType.String:
416
+ return "String";
417
+ }
418
+ throw new Error(`Uninitialized CoreSchemaView primitive type: ${svType}`);
419
+ }
420
+ function createECEnumerationFromSchemaView(svEnum, schema) {
421
+ return {
422
+ schema,
423
+ fullName: normalizeFullClassName(svEnum.fullName),
424
+ name: svEnum.name,
425
+ label: svEnum.label,
426
+ description: svEnum.description,
427
+ type: svEnum.primitiveType === SchemaViewPrimitiveType.Integer ? "Number" : "String",
428
+ isStrict: svEnum.isStrict,
429
+ enumerators: [...svEnum.getEnumerators()].map((e) => ({ name: e.name, label: e.label, value: e.value })),
430
+ };
431
+ }
432
+ function createECKoqFromSchemaView(svKoq, schema) {
433
+ return {
434
+ schema,
435
+ fullName: normalizeFullClassName(svKoq.fullName),
436
+ name: svKoq.name,
437
+ label: svKoq.label,
438
+ description: svKoq.description,
439
+ relativeError: svKoq.relativeError,
440
+ persistenceUnit: svKoq.persistenceUnit,
441
+ };
442
+ }
443
+ function createECPropertyCategoryFromSchemaView(svCategory, schema) {
444
+ return {
445
+ schema,
446
+ fullName: normalizeFullClassName(svCategory.fullName),
447
+ name: svCategory.name,
448
+ label: svCategory.label,
449
+ description: svCategory.description,
450
+ priority: svCategory.priority,
451
+ };
452
+ }
453
+ /** @internal */
454
+ export async function createECClassHierarchyResolver(imodel) {
455
+ const baseToDerivedMap = new Map();
456
+ const derivedToBaseMap = new Map();
457
+ const ecsql = `
458
+ SELECT
459
+ ec_classname(rel.SourceECInstanceId, 's.c'),
460
+ ec_classname(rel.TargetECInstanceId, 's.c')
461
+ FROM meta.ClassHasBaseClasses rel
462
+ `;
463
+ const reader = imodel.createQueryReader(ecsql);
464
+ for await (const row of reader) {
465
+ const derivedClass = row[0];
466
+ const baseClass = row[1];
467
+ let baseToDerivedEntry = baseToDerivedMap.get(baseClass);
468
+ if (!baseToDerivedEntry) {
469
+ baseToDerivedEntry = new Set();
470
+ baseToDerivedMap.set(baseClass, baseToDerivedEntry);
471
+ }
472
+ baseToDerivedEntry.add(derivedClass);
473
+ let derivedToBaseEntry = derivedToBaseMap.get(derivedClass);
474
+ if (!derivedToBaseEntry) {
475
+ derivedToBaseEntry = new Set();
476
+ derivedToBaseMap.set(derivedClass, derivedToBaseEntry);
477
+ }
478
+ derivedToBaseEntry.add(baseClass);
479
+ }
480
+ /**
481
+ * TODO: We don't really need this in schema provider, but maybe this function should become part of it? Would allow us to drop
482
+ * ECClassHierarchyInspector, whose implementation currently has to load schemas (this one doesn't).
483
+ */
484
+ function classDerivesFrom(derivedClassFullName, candidateBaseClassFullName) {
485
+ const baseClasses = derivedToBaseMap.get(derivedClassFullName);
486
+ return baseClasses
487
+ ? baseClasses.has(candidateBaseClassFullName) ||
488
+ baseClasses.values().some((baseClass) => classDerivesFrom(baseClass, candidateBaseClassFullName))
489
+ : false;
490
+ }
491
+ function getDerivedClassNames(classFullName, options) {
492
+ const derivedClasses = baseToDerivedMap.get(classFullName);
493
+ if (!derivedClasses) {
494
+ return [];
495
+ }
496
+ if (options?.onlyDirect) {
497
+ return [...derivedClasses];
498
+ }
499
+ const allDerivedClasses = new Set();
500
+ for (const derivedClass of derivedClasses) {
501
+ allDerivedClasses.add(derivedClass);
502
+ getDerivedClassNames(derivedClass, options).forEach((subDerivedClass) => allDerivedClasses.add(subDerivedClass));
503
+ }
504
+ return Array.from(allDerivedClasses);
505
+ }
506
+ return { classDerivesFrom, getDerivedClassNames };
507
+ }
59
508
  //# sourceMappingURL=Metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAcvD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAgC;IACrE,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9E,KAAK,UAAU,oBAAoB,CAAC,UAAkB;QACpD,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;QAChF,OAAO,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;IACD,KAAK,UAAU,kBAAkB,CAAC,UAAkB,EAAE,2BAAwC;QAC5F,mEAAmE;QACnE,IAAI,CAAC;YACH,OAAO,MAAM,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,iCAAiC;YACjC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC3G,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAC5C,OAAO,kBAAkB,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;gBACrE,CAAC;gBACD,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBAC3C,OAAO,SAAS,CAAC;gBACnB,CAAC;YACH,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK,CAAC,SAAS,CAAC,IAAI;YAClB,IAAI,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;gBAC9C,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { SchemaKey as CoreSchemaKey } from \"@itwin/ecschema-metadata\";\nimport { createECSchema } from \"./MetadataInternal.js\";\n\nimport type { Schema as CoreSchema } from \"@itwin/ecschema-metadata\";\nimport type { EC, ECSchemaProvider } from \"@itwin/presentation-shared\";\n\n/**\n * Defines input for `createECSchemaProvider`. Generally, this is an instance of [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/)\n * class from `@itwin/ecschema-metadata` package.\n * @public\n */\ninterface CoreSchemaContext {\n getSchema(key: CoreSchemaKey): Promise<CoreSchema | undefined>;\n}\n\n/**\n * Creates an `ECSchemaProvider` for given [SchemaContext](https://www.itwinjs.org/reference/ecschema-metadata/context/schemacontext/).\n *\n * Usage example:\n *\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * import { createECSchemaProvider } from \"@itwin/presentation-core-interop\";\n *\n * const imodel: IModelConnection = getIModel();\n * const schemaProvider = createECSchemaProvider(imodel.schemaContext);\n * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages\n * ```\n *\n * @public\n */\nexport function createECSchemaProvider(schemaContext: CoreSchemaContext): ECSchemaProvider {\n const schemaRequestsCache = new Map<string, Promise<EC.Schema | undefined>>();\n async function getSchemaUnprotected(schemaName: string) {\n const coreSchema = await schemaContext.getSchema(new CoreSchemaKey(schemaName));\n return coreSchema ? createECSchema(coreSchema) : undefined;\n }\n async function getSchemaProtected(schemaName: string, handledExistingSchemaErrors: Set<string>) {\n // workaround for https://github.com/iTwin/itwinjs-core/issues/6542\n try {\n return await getSchemaUnprotected(schemaName);\n } catch (e) {\n /* v8 ignore else -- @preserve */\n if (e instanceof Error) {\n if (e.message.includes(\"already exists within this cache\") && !handledExistingSchemaErrors.has(schemaName)) {\n handledExistingSchemaErrors.add(schemaName);\n return getSchemaProtected(schemaName, handledExistingSchemaErrors);\n }\n if (e.message.includes(\"schema not found\")) {\n return undefined;\n }\n }\n throw e;\n }\n }\n return {\n async getSchema(name) {\n let promise = schemaRequestsCache.get(name);\n if (!promise) {\n promise = getSchemaProtected(name, new Set());\n schemaRequestsCache.set(name, promise);\n }\n return promise;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../src/core-interop/Metadata.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MA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AAC;QAC7B,CAAC;QACD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA+B,CAAC;QACjE,KAAK,MAAM,YAAY,IAAI,cAAc,EAAE,CAAC;YAC1C,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACpC,oBAAoB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QACnH,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC;AACpD,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 { bufferTime, filter, firstValueFrom, map, mergeMap, share, Subject } from \"rxjs\";\nimport { SchemaViewPrimitiveType, StrengthDirection } from \"@itwin/ecschema-metadata\";\nimport { type EC, type ECSchemaProvider, normalizeFullClassName } from \"@itwin/presentation-shared\";\n\nimport type { SchemaView as CoreSchemaView } from \"@itwin/ecschema-metadata\";\nimport type { CoreECSqlReaderFactory } from \"./QueryExecutor.js\";\n\n/**\n * Subset of [SchemaView](https://www.itwinjs.org/reference/ecschema-metadata/context/schemaview/) API surface that\n * is `@public` and can be used by `createECSchemaProvider` function.\n *\n * @public\n */\ntype PublicCoreSchemaView = Pick<\n CoreSchemaView,\n | \"schemaToken\"\n | \"isOutdated\"\n | \"schemaCount\"\n | \"classCount\"\n | \"getSchema\"\n | \"getSchemaByAlias\"\n | \"getSchemas\"\n | \"findClass\"\n | \"findEnumeration\"\n | \"findKindOfQuantity\"\n | \"findPropertyCategory\"\n>;\n\n/**\n * A function that optionally takes a list of schema names and returns a `SchemaView`, containing details about the\n * requested schemas.\n *\n * If no schema names are provided, the function should return a `SchemaView` containing all available schemas.\n *\n * @public\n */\ntype CoreSchemaViewGetter = (props?: { schemas?: string[] }) => Promise<PublicCoreSchemaView>;\n\n/**\n * Accumulates schema names requested within the same frame and issues a single `getSchemaView` request for all of\n * them in the next one, returning each caller the batch's result. Used both by `createECSchemaProvider` and by\n * `createValueFormatter` (which resolves kind of quantity persistence units without needing the class hierarchy).\n *\n * @internal\n */\nexport function createBatchedSchemaViewGetter<TSchemaView>(imodel: {\n getSchemaView: (props?: { schemas?: string[] }) => Promise<TSchemaView>;\n}): (schemaName: string) => Promise<TSchemaView> {\n const schemaNameSubject = new Subject<string>();\n const schemaViewBatches = schemaNameSubject.pipe(\n bufferTime(0),\n filter((schemaNames) => schemaNames.length > 0),\n mergeMap(async (schemaNames) => {\n const schemas = new Set(schemaNames);\n return { schemas, schemaView: await imodel.getSchemaView({ schemas: [...schemas] }) };\n }),\n share(),\n );\n return async function getSchemaView(schemaName: string): Promise<TSchemaView> {\n const schemaView = firstValueFrom(\n schemaViewBatches.pipe(\n filter((batch) => batch.schemas.has(schemaName)),\n map((batch) => batch.schemaView),\n ),\n );\n schemaNameSubject.next(schemaName);\n return schemaView;\n };\n}\n\n/**\n * Creates an `ECSchemaProvider` for a given iModel with [SchemaView](https://www.itwinjs.org/reference/ecschema-metadata/context/schemaview/)\n * getter and query reader factory.\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);\n * // the created schema provider may be used in `@itwin/presentation-hierarchies` and other Presentation packages\n * ```\n *\n * @public\n */\nexport function createECSchemaProvider(\n imodel: { getSchemaView: CoreSchemaViewGetter } & CoreECSqlReaderFactory,\n): ECSchemaProvider {\n const getSchemaView = createBatchedSchemaViewGetter(imodel);\n\n // Ensures we only create a single `ECClassHierarchyResolver` for the iModel, which is used to resolve derived classes for all schemas.\n // Cache the promise (not the resolved value) so concurrent `getSchema` calls share one `createECClassHierarchyResolver` invocation.\n let cachedClassHierarchyResolverPromise: Promise<ECClassHierarchyResolver> | undefined;\n // Set once the resolver promise settles. Allows `classDerivesFrom` to answer synchronously after the hierarchy is loaded.\n let cachedClassHierarchyResolver: ECClassHierarchyResolver | undefined;\n function getClassHierarchyResolver(): ECClassHierarchyResolver | Promise<ECClassHierarchyResolver> {\n if (cachedClassHierarchyResolver) {\n return cachedClassHierarchyResolver;\n }\n cachedClassHierarchyResolverPromise ??= createECClassHierarchyResolver(imodel).then((resolver) => {\n cachedClassHierarchyResolver = resolver;\n return resolver;\n });\n return cachedClassHierarchyResolverPromise;\n }\n\n async function getSchemaProviderContext(schemaName: string) {\n const [classHierarchyResolver, schemaView] = await Promise.all([\n getClassHierarchyResolver(),\n getSchemaView(schemaName),\n ]);\n return { classHierarchyResolver, schemaView };\n }\n\n // Cache the resolved schema by name so repeated `getSchema`/`getClass` calls reuse it instead of issuing a new\n // `getSchemaView` request each time. The cached promise doubles as an in-flight guard: concurrent\n // first-time requests for the same schema share it (and its underlying `getSchemaView` request) instead of each\n // building the schema. The entry is retained until the schema view it was built from is marked outdated by the host\n // (a newer view has replaced it), at which point the next access refreshes it.\n const schemaCache = new Map<string, Promise<{ schemaView: PublicCoreSchemaView; schema: EC.Schema | undefined }>>();\n async function fetchSchema(name: string) {\n // Cache built `EC.Class` objects (by full name) for this schema, so repeated accesses (e.g. the\n // `EC.Property.class` getter, invoked once per grouped node) reuse a single class instead of rebuilding it from\n // the schema view every time. Scoped to the fetch so a later refetch (when the view is outdated) starts fresh.\n const classCache = new Map<string, EC.Class>();\n const entry = (async () => {\n const { classHierarchyResolver, schemaView } = await getSchemaProviderContext(name);\n const svSchema = schemaView.getSchema(name);\n const schema = svSchema\n ? createECSchemaFromSchemaView(svSchema, { schemaView, classHierarchyResolver, classCache })\n : undefined;\n return { schemaView, schema };\n })();\n schemaCache.set(name, entry);\n // Drop rejected entries so a transient failure doesn't get cached permanently.\n /* v8 ignore next 4 -- defensive cleanup for rejected cache entries while a newer entry may have already replaced this one */\n entry.catch(() => {\n if (schemaCache.get(name) === entry) {\n schemaCache.delete(name);\n }\n });\n return entry;\n }\n\n return {\n async getSchema(name) {\n const cached = schemaCache.get(name);\n const entry = await (cached ?? fetchSchema(name));\n return entry.schemaView.isOutdated ? (await fetchSchema(name)).schema : entry.schema;\n },\n classDerivesFrom(\n derivedClassFullName: EC.FullClassNameDotNotation,\n candidateBaseClassFullName: EC.FullClassNameDotNotation,\n ): Promise<boolean> | boolean {\n // A class always derives from itself. This matches the semantics of the deprecated `ECClassHierarchyInspector`.\n if (derivedClassFullName === candidateBaseClassFullName) {\n return true;\n }\n const resolver = getClassHierarchyResolver();\n return resolver instanceof Promise\n ? resolver.then((r) => r.classDerivesFrom(derivedClassFullName, candidateBaseClassFullName))\n : resolver.classDerivesFrom(derivedClassFullName, candidateBaseClassFullName);\n },\n };\n}\n\ninterface SchemaViewProviderContext {\n schemaView: PublicCoreSchemaView;\n classHierarchyResolver: ECClassHierarchyResolver;\n schema: EC.Schema;\n /** Shared cache of built `EC.Class` objects keyed by full class name, to avoid rebuilding them on every access. */\n classCache: Map<string, EC.Class>;\n}\n\nexport function createECSchemaFromSchemaView(\n svSchema: CoreSchemaView.Schema,\n context: Omit<SchemaViewProviderContext, \"schema\">,\n): EC.Schema {\n const ecSchema: EC.Schema = {\n name: svSchema.name,\n description: svSchema.description,\n version: { read: svSchema.readVersion, write: svSchema.writeVersion, minor: svSchema.minorVersion },\n isHidden: svSchema.isHidden,\n getClass(name) {\n const svClass = svSchema.getClass(name);\n return svClass ? getECClassFromSchemaView(svClass, { ...context, schema: ecSchema }) : undefined;\n },\n getEnumeration(name) {\n const svEnum = svSchema.getEnumeration(name);\n return svEnum ? createECEnumerationFromSchemaView(svEnum, ecSchema) : undefined;\n },\n getKindOfQuantity(name) {\n const svKoq = svSchema.getKindOfQuantity(name);\n return svKoq ? createECKoqFromSchemaView(svKoq, ecSchema) : undefined;\n },\n getPropertyCategory(name) {\n const svCategory = svSchema.getPropertyCategory(name);\n return svCategory ? createECPropertyCategoryFromSchemaView(svCategory, ecSchema) : undefined;\n },\n };\n return ecSchema;\n}\n\n/**\n * Cache-aware entry point for building an `EC.Class` from a schema view class: returns a previously built class for\n * the same full name, otherwise builds one via `createECClassFromSchemaView` and stores it in the context's cache.\n */\nfunction getECClassFromSchemaView(svClass: CoreSchemaView.Class, context: SchemaViewProviderContext): EC.Class {\n // Key by the schema view's raw full name: it is a stable identifier for the class, so we avoid normalizing it on\n // every (hot) cache hit. `createECClassFromSchemaView` normalizes once, on a miss, for the `EC.Class.fullName` field.\n const cached = context.classCache.get(svClass.fullName);\n if (cached) {\n return cached;\n }\n const ecClass = createECClassFromSchemaView(svClass, context);\n context.classCache.set(svClass.fullName, ecClass);\n return ecClass;\n}\n\nexport function createECClassFromSchemaView(\n svClass: CoreSchemaView.Class,\n context: SchemaViewProviderContext,\n): EC.Class {\n const { classHierarchyResolver, schema } = context;\n const fullName = normalizeFullClassName(svClass.fullName);\n const ecClass: EC.Class = {\n schema,\n fullName,\n name: svClass.name,\n label: svClass.label,\n description: svClass.description,\n isHidden: svClass.isHidden,\n isEntityClass(): this is EC.EntityClass {\n return svClass.isEntity();\n },\n isRelationshipClass(): this is EC.RelationshipClass {\n return svClass.isRelationship();\n },\n isStructClass(): this is EC.StructClass {\n return svClass.isStruct();\n },\n isMixin(): this is EC.Mixin {\n return svClass.isMixin();\n },\n get baseClass(): EC.Class | undefined {\n return svClass.baseClass\n ? getECClassFromSchemaView(svClass.baseClass, {\n ...context,\n schema: useOrCreateSchema(svClass.baseClass.schema, context),\n })\n : undefined;\n },\n is(classOrClassName: EC.Class | string, schemaName?: string): boolean {\n if (typeof classOrClassName === \"string\") {\n return svClass.is(`${schemaName!}.${classOrClassName}`);\n }\n return svClass.is(classOrClassName.fullName);\n },\n getProperty(name: string): EC.Property | undefined {\n const svProp = svClass.getProperty(name);\n return svProp ? createECPropertyFromSchemaView(svProp, ecClass, context) : undefined;\n },\n getProperties(): EC.Property[] {\n return svClass.getProperties().map((p) => createECPropertyFromSchemaView(p, ecClass, context));\n },\n getOwnProperties(): EC.Property[] {\n return svClass.getOwnProperties().map((p) => createECPropertyFromSchemaView(p, ecClass, context));\n },\n getDerivedClassNames(props?: { onlyDirect?: boolean }): EC.FullClassNameDotNotation[] {\n return classHierarchyResolver.getDerivedClassNames(fullName, props);\n },\n };\n\n if (svClass.isEntity()) {\n const ecEntity: EC.EntityClass = {\n ...ecClass,\n getMixins(): EC.Mixin[] {\n return svClass.mixins.map((m) =>\n getECClassFromSchemaView(m, { ...context, schema: useOrCreateSchema(m.schema, context) }),\n );\n },\n };\n return ecEntity;\n }\n\n if (svClass.isRelationship()) {\n const ecRel: EC.RelationshipClass = {\n ...ecClass,\n direction: svClass.strengthDirection === StrengthDirection.Forward ? \"Forward\" : \"Backward\",\n source: svClass.source\n ? createECRelConstraintFromSchemaView(svClass.source, context)\n : createEmptyRelConstraint(),\n target: svClass.target\n ? createECRelConstraintFromSchemaView(svClass.target, context)\n : createEmptyRelConstraint(),\n };\n return ecRel;\n }\n\n return ecClass;\n}\n\nfunction useOrCreateSchema(svSchema: CoreSchemaView.Schema, context: SchemaViewProviderContext): EC.Schema {\n const { schema: currentSchema, ...schemalessContext } = context;\n if (svSchema.name === currentSchema.name) {\n return currentSchema;\n }\n return createECSchemaFromSchemaView(svSchema, schemalessContext);\n}\n\nfunction createEmptyRelConstraint(): EC.RelationshipConstraint {\n return {\n multiplicity: { lowerLimit: 0, upperLimit: 0 },\n polymorphic: false,\n constraintClasses: [],\n abstractConstraint: undefined,\n };\n}\n\nfunction createECRelConstraintFromSchemaView(\n svConstraint: CoreSchemaView.RelConstraint,\n context: SchemaViewProviderContext,\n): EC.RelationshipConstraint {\n return {\n multiplicity: {\n lowerLimit: svConstraint.multiplicityLower,\n // `SchemaView` reports an unbounded upper limit as `0`.\n upperLimit: svConstraint.multiplicityUpper === 0 ? \"unbounded\" : svConstraint.multiplicityUpper,\n },\n polymorphic: svConstraint.polymorphic,\n get constraintClasses() {\n return svConstraint.constraintClasses.map((c) =>\n getECClassFromSchemaView(c, { ...context, schema: useOrCreateSchema(c.schema, context) }),\n );\n },\n get abstractConstraint(): EC.EntityClass | EC.Mixin | EC.RelationshipClass | undefined {\n // `SchemaView` only exposes an explicitly-defined abstract constraint. To match EC semantics (and the\n // standard `RelationshipConstraint` implementation), fall back to the sole constraint class when there's exactly one.\n const svClass =\n svConstraint.abstractConstraint ??\n (svConstraint.constraintClasses.length === 1 ? svConstraint.constraintClasses[0] : undefined);\n if (!svClass) {\n return undefined;\n }\n return getECClassFromSchemaView(svClass, { ...context, schema: useOrCreateSchema(svClass.schema, context) });\n },\n };\n}\n\nexport function createECPropertyFromSchemaView(\n svProp: CoreSchemaView.Property,\n ecClass: EC.Class,\n context: SchemaViewProviderContext,\n): EC.Property {\n const base: EC.Property = {\n // `svProp.declaringClass` is the class that declared or contributed this property (a base class for an\n // inherited property, or a mixin for a mixin-contributed one). It's `undefined` only for view properties,\n // in which case we fall back to the class the property was enumerated from.\n get class(): EC.Class {\n return svProp.declaringClass\n ? getECClassFromSchemaView(svProp.declaringClass, {\n ...context,\n schema: useOrCreateSchema(svProp.declaringClass.schema, context),\n })\n : ecClass;\n },\n name: svProp.name,\n description: svProp.description,\n label: svProp.label,\n isHidden: svProp.isHidden,\n get category(): EC.PropertyCategory | undefined {\n return svProp.category\n ? createECPropertyCategoryFromSchemaView(svProp.category, useOrCreateSchema(svProp.category.schema, context))\n : undefined;\n },\n isArray(): this is EC.ArrayProperty {\n return svProp.isArray();\n },\n isStruct(): this is EC.StructProperty {\n return false;\n },\n isPrimitive(): this is EC.PrimitiveProperty {\n return false;\n },\n isEnumeration(): this is EC.EnumerationProperty {\n return false;\n },\n isNavigation(): this is EC.NavigationProperty {\n return false;\n },\n };\n\n if (svProp.isNavigation()) {\n return {\n ...base,\n isNavigation(): this is EC.NavigationProperty {\n return true;\n },\n get direction() {\n return svProp.direction === StrengthDirection.Forward ? \"Forward\" : \"Backward\";\n },\n get relationshipClass(): EC.RelationshipClass {\n return getECClassFromSchemaView(svProp.relationshipClass, {\n ...context,\n schema: useOrCreateSchema(svProp.relationshipClass.schema, context),\n }) as EC.RelationshipClass;\n },\n } satisfies EC.NavigationProperty;\n }\n\n // Check enumeration before primitive (enum is a facet of primitive in CoreSchemaView, but separate in EC)\n if (svProp.isEnumeration()) {\n const arrayFields = svProp.isArray()\n ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }\n : undefined;\n return {\n ...base,\n ...arrayFields,\n isEnumeration(): this is EC.EnumerationProperty {\n return true;\n },\n isArray(): this is EC.ArrayProperty {\n return svProp.isArray();\n },\n get extendedTypeName() {\n return svProp.extendedTypeName;\n },\n get enumeration(): EC.Enumeration | undefined {\n return svProp.enumeration\n ? createECEnumerationFromSchemaView(svProp.enumeration, useOrCreateSchema(svProp.enumeration.schema, context))\n : undefined;\n },\n } satisfies EC.EnumerationProperty | EC.EnumerationArrayProperty;\n }\n\n if (svProp.isPrimitive()) {\n const arrayFields = svProp.isArray()\n ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }\n : undefined;\n return {\n ...base,\n ...arrayFields,\n isPrimitive(): this is EC.PrimitiveProperty {\n return true;\n },\n isArray(): this is EC.ArrayProperty {\n return svProp.isArray();\n },\n get primitiveType() {\n return mapSchemaViewPrimitiveType(svProp.primitiveType);\n },\n get extendedTypeName() {\n return svProp.extendedTypeName;\n },\n get kindOfQuantity(): EC.KindOfQuantity | undefined {\n return svProp.kindOfQuantity\n ? createECKoqFromSchemaView(svProp.kindOfQuantity, useOrCreateSchema(svProp.kindOfQuantity.schema, context))\n : undefined;\n },\n } satisfies EC.PrimitiveProperty | EC.PrimitiveArrayProperty;\n }\n\n if (svProp.isStruct()) {\n const arrayFields = svProp.isArray()\n ? { minOccurs: svProp.arrayMinOccurs ?? 0, maxOccurs: svProp.arrayMaxOccurs }\n : undefined;\n return {\n ...base,\n ...arrayFields,\n isStruct(): this is EC.StructProperty {\n return true;\n },\n isArray(): this is EC.ArrayProperty {\n return svProp.isArray();\n },\n get structClass(): EC.StructClass {\n return getECClassFromSchemaView(svProp.structClass, {\n ...context,\n schema: useOrCreateSchema(svProp.structClass.schema, context),\n });\n },\n } satisfies EC.StructProperty | EC.StructArrayProperty;\n }\n\n throw new Error(\n `Unexpected property type for ${svProp.declaringClass ? svProp.declaringClass.fullName : \"<ECCView>\"}.${svProp.name}`,\n );\n}\n\nfunction mapSchemaViewPrimitiveType(svType: SchemaViewPrimitiveType): EC.PrimitiveType {\n switch (svType) {\n case SchemaViewPrimitiveType.Binary:\n return \"Binary\";\n case SchemaViewPrimitiveType.Boolean:\n return \"Boolean\";\n case SchemaViewPrimitiveType.DateTime:\n return \"DateTime\";\n case SchemaViewPrimitiveType.Double:\n return \"Double\";\n case SchemaViewPrimitiveType.IGeometry:\n return \"IGeometry\";\n case SchemaViewPrimitiveType.Integer:\n return \"Integer\";\n case SchemaViewPrimitiveType.Long:\n return \"Long\";\n case SchemaViewPrimitiveType.Point2d:\n return \"Point2d\";\n case SchemaViewPrimitiveType.Point3d:\n return \"Point3d\";\n case SchemaViewPrimitiveType.String:\n return \"String\";\n }\n throw new Error(`Uninitialized CoreSchemaView primitive type: ${svType}`);\n}\n\nfunction createECEnumerationFromSchemaView(svEnum: CoreSchemaView.Enumeration, schema: EC.Schema): EC.Enumeration {\n return {\n schema,\n fullName: normalizeFullClassName(svEnum.fullName),\n name: svEnum.name,\n label: svEnum.label,\n description: svEnum.description,\n type: svEnum.primitiveType === SchemaViewPrimitiveType.Integer ? \"Number\" : \"String\",\n isStrict: svEnum.isStrict,\n enumerators: [...svEnum.getEnumerators()].map((e) => ({ name: e.name, label: e.label, value: e.value })),\n };\n}\n\nfunction createECKoqFromSchemaView(svKoq: CoreSchemaView.KindOfQuantity, schema: EC.Schema): EC.KindOfQuantity {\n return {\n schema,\n fullName: normalizeFullClassName(svKoq.fullName),\n name: svKoq.name,\n label: svKoq.label,\n description: svKoq.description,\n relativeError: svKoq.relativeError,\n persistenceUnit: svKoq.persistenceUnit,\n };\n}\n\nfunction createECPropertyCategoryFromSchemaView(\n svCategory: CoreSchemaView.PropertyCategory,\n schema: EC.Schema,\n): EC.PropertyCategory {\n return {\n schema,\n fullName: normalizeFullClassName(svCategory.fullName),\n name: svCategory.name,\n label: svCategory.label,\n description: svCategory.description,\n priority: svCategory.priority,\n };\n}\n\n/** @internal */\nexport interface ECClassHierarchyResolver {\n /** Check if the derived class derives from the candidate base class. */\n classDerivesFrom(\n derivedClassFullName: EC.FullClassNameDotNotation,\n candidateBaseClassFullName: EC.FullClassNameDotNotation,\n ): boolean;\n /** Get names of all derived classes of the specified class. */\n getDerivedClassNames(\n classFullName: EC.FullClassNameDotNotation,\n options?: { onlyDirect?: boolean },\n ): EC.FullClassNameDotNotation[];\n}\n\n/** @internal */\nexport async function createECClassHierarchyResolver(\n imodel: CoreECSqlReaderFactory,\n): Promise<ECClassHierarchyResolver> {\n const baseToDerivedMap = new Map<EC.FullClassNameDotNotation, Set<EC.FullClassNameDotNotation>>();\n const derivedToBaseMap = new Map<EC.FullClassNameDotNotation, Set<EC.FullClassNameDotNotation>>();\n const ecsql = `\n SELECT\n ec_classname(rel.SourceECInstanceId, 's.c'),\n ec_classname(rel.TargetECInstanceId, 's.c')\n FROM meta.ClassHasBaseClasses rel\n `;\n const reader = imodel.createQueryReader(ecsql);\n for await (const row of reader) {\n const derivedClass = row[0] as EC.FullClassNameDotNotation;\n const baseClass = row[1] as EC.FullClassNameDotNotation;\n\n let baseToDerivedEntry = baseToDerivedMap.get(baseClass);\n if (!baseToDerivedEntry) {\n baseToDerivedEntry = new Set<EC.FullClassNameDotNotation>();\n baseToDerivedMap.set(baseClass, baseToDerivedEntry);\n }\n baseToDerivedEntry.add(derivedClass);\n\n let derivedToBaseEntry = derivedToBaseMap.get(derivedClass);\n if (!derivedToBaseEntry) {\n derivedToBaseEntry = new Set<EC.FullClassNameDotNotation>();\n derivedToBaseMap.set(derivedClass, derivedToBaseEntry);\n }\n derivedToBaseEntry.add(baseClass);\n }\n\n /**\n * TODO: We don't really need this in schema provider, but maybe this function should become part of it? Would allow us to drop\n * ECClassHierarchyInspector, whose implementation currently has to load schemas (this one doesn't).\n */\n function classDerivesFrom(\n derivedClassFullName: EC.FullClassNameDotNotation,\n candidateBaseClassFullName: EC.FullClassNameDotNotation,\n ): boolean {\n const baseClasses = derivedToBaseMap.get(derivedClassFullName);\n return baseClasses\n ? baseClasses.has(candidateBaseClassFullName) ||\n baseClasses.values().some((baseClass) => classDerivesFrom(baseClass, candidateBaseClassFullName))\n : false;\n }\n\n function getDerivedClassNames(\n classFullName: EC.FullClassNameDotNotation,\n options?: { onlyDirect?: boolean },\n ): EC.FullClassNameDotNotation[] {\n const derivedClasses = baseToDerivedMap.get(classFullName);\n if (!derivedClasses) {\n return [];\n }\n if (options?.onlyDirect) {\n return [...derivedClasses];\n }\n const allDerivedClasses = new Set<EC.FullClassNameDotNotation>();\n for (const derivedClass of derivedClasses) {\n allDerivedClasses.add(derivedClass);\n getDerivedClassNames(derivedClass, options).forEach((subDerivedClass) => allDerivedClasses.add(subDerivedClass));\n }\n return Array.from(allDerivedClasses);\n }\n\n return { classDerivesFrom, getDerivedClassNames };\n}\n"]}