@itwin/presentation-core-interop 0.1.2 → 0.2.1

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 +19 -0
  2. package/lib/cjs/core-interop/Metadata.d.ts.map +1 -1
  3. package/lib/cjs/core-interop/Metadata.js +7 -1
  4. package/lib/cjs/core-interop/Metadata.js.map +1 -1
  5. package/lib/cjs/core-interop/QueryExecutor.d.ts.map +1 -1
  6. package/lib/cjs/core-interop/QueryExecutor.js +5 -1
  7. package/lib/cjs/core-interop/QueryExecutor.js.map +1 -1
  8. package/lib/esm/core-interop/Metadata.d.ts.map +1 -1
  9. package/lib/esm/core-interop/Metadata.js +7 -1
  10. package/lib/esm/core-interop/Metadata.js.map +1 -1
  11. package/lib/esm/core-interop/QueryExecutor.d.ts.map +1 -1
  12. package/lib/esm/core-interop/QueryExecutor.js +5 -1
  13. package/lib/esm/core-interop/QueryExecutor.js.map +1 -1
  14. package/package.json +12 -12
  15. package/.mocharc.json +0 -8
  16. package/.nycrc +0 -14
  17. package/api/presentation-core-interop.api.md +0 -38
  18. package/api/presentation-core-interop.exports.csv +0 -7
  19. package/eslint.config.js +0 -14
  20. package/lib/cjs/test/Formatting.test.d.ts +0 -2
  21. package/lib/cjs/test/Formatting.test.d.ts.map +0 -1
  22. package/lib/cjs/test/Formatting.test.js +0 -282
  23. package/lib/cjs/test/Formatting.test.js.map +0 -1
  24. package/lib/cjs/test/Logging.test.d.ts +0 -2
  25. package/lib/cjs/test/Logging.test.d.ts.map +0 -1
  26. package/lib/cjs/test/Logging.test.js +0 -57
  27. package/lib/cjs/test/Logging.test.js.map +0 -1
  28. package/lib/cjs/test/Metadata.test.d.ts +0 -2
  29. package/lib/cjs/test/Metadata.test.d.ts.map +0 -1
  30. package/lib/cjs/test/Metadata.test.js +0 -684
  31. package/lib/cjs/test/Metadata.test.js.map +0 -1
  32. package/lib/cjs/test/QueryExecutor.test.d.ts +0 -2
  33. package/lib/cjs/test/QueryExecutor.test.d.ts.map +0 -1
  34. package/lib/cjs/test/QueryExecutor.test.js +0 -178
  35. package/lib/cjs/test/QueryExecutor.test.js.map +0 -1
  36. package/lib/cjs/test/Transactions.test.d.ts +0 -2
  37. package/lib/cjs/test/Transactions.test.d.ts.map +0 -1
  38. package/lib/cjs/test/Transactions.test.js +0 -73
  39. package/lib/cjs/test/Transactions.test.js.map +0 -1
  40. package/lib/cjs/test/index.d.ts +0 -2
  41. package/lib/cjs/test/index.d.ts.map +0 -1
  42. package/lib/cjs/test/index.js +0 -43
  43. package/lib/cjs/test/index.js.map +0 -1
  44. package/lib/esm/test/Formatting.test.d.ts +0 -2
  45. package/lib/esm/test/Formatting.test.d.ts.map +0 -1
  46. package/lib/esm/test/Formatting.test.js +0 -277
  47. package/lib/esm/test/Formatting.test.js.map +0 -1
  48. package/lib/esm/test/Logging.test.d.ts +0 -2
  49. package/lib/esm/test/Logging.test.d.ts.map +0 -1
  50. package/lib/esm/test/Logging.test.js +0 -52
  51. package/lib/esm/test/Logging.test.js.map +0 -1
  52. package/lib/esm/test/Metadata.test.d.ts +0 -2
  53. package/lib/esm/test/Metadata.test.d.ts.map +0 -1
  54. package/lib/esm/test/Metadata.test.js +0 -679
  55. package/lib/esm/test/Metadata.test.js.map +0 -1
  56. package/lib/esm/test/QueryExecutor.test.d.ts +0 -2
  57. package/lib/esm/test/QueryExecutor.test.d.ts.map +0 -1
  58. package/lib/esm/test/QueryExecutor.test.js +0 -173
  59. package/lib/esm/test/QueryExecutor.test.js.map +0 -1
  60. package/lib/esm/test/Transactions.test.d.ts +0 -2
  61. package/lib/esm/test/Transactions.test.d.ts.map +0 -1
  62. package/lib/esm/test/Transactions.test.js +0 -68
  63. package/lib/esm/test/Transactions.test.js.map +0 -1
  64. package/lib/esm/test/index.d.ts +0 -2
  65. package/lib/esm/test/index.d.ts.map +0 -1
  66. package/lib/esm/test/index.js +0 -15
  67. package/lib/esm/test/index.js.map +0 -1
  68. package/src/core-interop/Formatting.ts +0 -194
  69. package/src/core-interop/Logging.ts +0 -58
  70. package/src/core-interop/Metadata.ts +0 -62
  71. package/src/core-interop/MetadataInternal.ts +0 -413
  72. package/src/core-interop/QueryExecutor.ts +0 -122
  73. package/src/core-interop/Transactions.ts +0 -92
  74. package/src/presentation-core-interop.ts +0 -10
  75. package/src/test/Formatting.test.ts +0 -358
  76. package/src/test/Logging.test.ts +0 -59
  77. package/src/test/Metadata.test.ts +0 -786
  78. package/src/test/QueryExecutor.test.ts +0 -217
  79. package/src/test/Transactions.test.ts +0 -74
  80. package/src/test/index.ts +0 -17
  81. package/tsconfig.cjs.json +0 -7
  82. package/tsconfig.esm.json +0 -7
  83. package/tsconfig.json +0 -14
@@ -1,413 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
-
6
- import { assert } from "@itwin/core-bentley";
7
- import {
8
- ECClass as CoreClass,
9
- EntityClass as CoreEntityClass,
10
- Enumeration as CoreEnumeration,
11
- EnumerationArrayProperty as CoreEnumerationArrayProperty,
12
- EnumerationProperty as CoreEnumerationProperty,
13
- KindOfQuantity as CoreKindOfQuantity,
14
- Mixin as CoreMixin,
15
- NavigationProperty as CoreNavigationProperty,
16
- PrimitiveArrayProperty as CorePrimitiveArrayProperty,
17
- PrimitiveProperty as CorePrimitiveProperty,
18
- Property as CoreProperty,
19
- RelationshipClass as CoreRelationshipClass,
20
- RelationshipConstraint as CoreRelationshipConstraint,
21
- Schema as CoreSchema,
22
- SchemaItem as CoreSchemaItem,
23
- StructArrayProperty as CoreStructArrayProperty,
24
- StructClass as CoreStructClass,
25
- StructProperty as CoreStructProperty,
26
- LazyLoadedSchemaItem,
27
- PrimitiveType,
28
- SchemaItemType,
29
- StrengthDirection,
30
- } from "@itwin/ecschema-metadata";
31
- import { EC } from "@itwin/presentation-shared";
32
-
33
- /** @internal */
34
- export function createECSchema(schema: CoreSchema): EC.Schema {
35
- return {
36
- name: schema.name,
37
- async getClass(name) {
38
- const item = await schema.getItem<CoreClass>(name);
39
- return item ? createECClass(item, this) : undefined;
40
- },
41
- };
42
- }
43
-
44
- abstract class ECSchemaItemImpl<TCoreSchemaItem extends CoreSchemaItem> implements EC.SchemaItem {
45
- private _schema: EC.Schema;
46
- protected constructor(
47
- protected _coreSchemaItem: TCoreSchemaItem,
48
- schema?: EC.Schema,
49
- ) {
50
- this._schema = schema ?? createECSchema(this._coreSchemaItem.schema);
51
- }
52
- public get schema() {
53
- return this._schema;
54
- }
55
- public get fullName() {
56
- return this._coreSchemaItem.fullName;
57
- }
58
- public get name() {
59
- return this._coreSchemaItem.name;
60
- }
61
- public get label() {
62
- return this._coreSchemaItem.label;
63
- }
64
- }
65
-
66
- /** @internal */
67
- export function createECClass(coreClass: CoreClass, schema?: EC.Schema): EC.Class {
68
- switch (coreClass.schemaItemType) {
69
- case SchemaItemType.EntityClass:
70
- return new ECEntityClassImpl(coreClass as CoreEntityClass, schema);
71
- case SchemaItemType.RelationshipClass:
72
- return new ECRelationshipClassImpl(coreClass as CoreRelationshipClass, schema);
73
- case SchemaItemType.StructClass:
74
- return new ECStructClassImpl(coreClass as CoreStructClass, schema);
75
- case SchemaItemType.Mixin:
76
- return new ECMixinImpl(coreClass as CoreMixin, schema);
77
- }
78
- throw new Error(`Invalid class type "${coreClass.schemaItemType}" for class ${coreClass.fullName}`);
79
- }
80
-
81
- abstract class ECClassImpl<TCoreClass extends CoreClass> extends ECSchemaItemImpl<TCoreClass> implements EC.Class {
82
- protected constructor(coreClass: TCoreClass, schema?: EC.Schema) {
83
- super(coreClass, schema);
84
- }
85
- public isEntityClass(): this is EC.EntityClass {
86
- return false;
87
- }
88
- public isRelationshipClass(): this is EC.RelationshipClass {
89
- return false;
90
- }
91
- public isStructClass(): this is EC.StructClass {
92
- return false;
93
- }
94
- public isMixin(): this is EC.Mixin {
95
- return false;
96
- }
97
- public async is(classOrClassName: EC.Class | string, schemaName?: string) {
98
- if (typeof classOrClassName === "string") {
99
- return this._coreSchemaItem.is(classOrClassName, schemaName!);
100
- }
101
- return this._coreSchemaItem.is(classOrClassName.name, classOrClassName.schema.name);
102
- }
103
- public async getProperty(name: string): Promise<EC.Property | undefined> {
104
- const coreProperty = await this._coreSchemaItem.getProperty(name, true);
105
- return coreProperty ? createECProperty(coreProperty, this) : undefined;
106
- }
107
- public async getProperties(): Promise<Array<EC.Property>> {
108
- const coreProperties = await this._coreSchemaItem.getProperties();
109
- return coreProperties.map((coreProperty) => createECProperty(coreProperty, this));
110
- }
111
- }
112
-
113
- class ECEntityClassImpl extends ECClassImpl<CoreEntityClass> implements EC.EntityClass {
114
- constructor(coreClass: CoreEntityClass, schema?: EC.Schema) {
115
- super(coreClass, schema);
116
- }
117
- public override isEntityClass(): this is EC.EntityClass {
118
- return true;
119
- }
120
- }
121
-
122
- class ECRelationshipClassImpl extends ECClassImpl<CoreRelationshipClass> implements EC.RelationshipClass {
123
- constructor(coreClass: CoreRelationshipClass, schema?: EC.Schema) {
124
- super(coreClass, schema);
125
- }
126
- public override isRelationshipClass(): this is EC.RelationshipClass {
127
- return true;
128
- }
129
- public get direction() {
130
- switch (this._coreSchemaItem.strengthDirection) {
131
- case StrengthDirection.Forward:
132
- return "Forward";
133
- case StrengthDirection.Backward:
134
- return "Backward";
135
- }
136
- }
137
- public get source() {
138
- return new ECRelationshipConstraintImpl(this._coreSchemaItem.source, this.schema);
139
- }
140
- public get target() {
141
- return new ECRelationshipConstraintImpl(this._coreSchemaItem.target, this.schema);
142
- }
143
- }
144
-
145
- class ECStructClassImpl extends ECClassImpl<CoreStructClass> implements EC.StructClass {
146
- constructor(coreClass: CoreStructClass, schema?: EC.Schema) {
147
- super(coreClass, schema);
148
- }
149
- public override isStructClass(): this is EC.StructClass {
150
- return true;
151
- }
152
- }
153
-
154
- class ECMixinImpl extends ECClassImpl<CoreMixin> implements EC.Mixin {
155
- constructor(coreClass: CoreMixin, schema?: EC.Schema) {
156
- super(coreClass, schema);
157
- }
158
- public override isMixin(): this is EC.Mixin {
159
- return true;
160
- }
161
- }
162
-
163
- /** @internal */
164
- export function createECProperty(coreProperty: CoreProperty, ecClass: EC.Class): EC.Property {
165
- if (coreProperty.isArray()) {
166
- if (coreProperty.isPrimitive()) {
167
- return new ECPrimitivesArrayPropertyImpl(coreProperty, ecClass);
168
- }
169
- if (coreProperty.isEnumeration()) {
170
- return new ECEnumerationArrayPropertyImpl(coreProperty, ecClass);
171
- }
172
- return new ECStructArrayPropertyImpl(coreProperty, ecClass);
173
- }
174
- if (coreProperty.isStruct()) {
175
- return new ECStructPropertyImpl(coreProperty, ecClass);
176
- }
177
- if (coreProperty.isEnumeration()) {
178
- return new ECEnumerationPropertyImpl(coreProperty, ecClass);
179
- }
180
- if (coreProperty.isNavigation()) {
181
- return new ECNavigationPropertyImpl(coreProperty, ecClass);
182
- }
183
- assert(coreProperty.isPrimitive());
184
- return new ECPrimitivePropertyImpl(coreProperty, ecClass);
185
- }
186
-
187
- abstract class ECPropertyImpl<TCoreProperty extends CoreProperty> implements EC.Property {
188
- protected constructor(
189
- protected _coreProperty: TCoreProperty,
190
- protected _class: EC.Class,
191
- ) {}
192
- public isArray(): this is EC.ArrayProperty {
193
- return false;
194
- }
195
- public isStruct(): this is EC.StructProperty {
196
- return false;
197
- }
198
- public isPrimitive(): this is EC.PrimitiveProperty {
199
- return false;
200
- }
201
- public isEnumeration(): this is EC.EnumerationProperty {
202
- return false;
203
- }
204
- public isNavigation(): this is EC.NavigationProperty {
205
- return false;
206
- }
207
- public get class() {
208
- return this._class;
209
- }
210
- public get name() {
211
- return this._coreProperty.name;
212
- }
213
- public get label() {
214
- return this._coreProperty.label;
215
- }
216
- public get kindOfQuantity(): Promise<EC.KindOfQuantity | undefined> {
217
- return createFromOptionalLazyLoaded(this._coreProperty.kindOfQuantity, (coreKindOfQuantity) => new ECKindOfQuantityImpl(coreKindOfQuantity));
218
- }
219
- }
220
-
221
- class ECPrimitivePropertyImpl<TCoreProperty extends CorePrimitiveProperty> extends ECPropertyImpl<TCoreProperty> implements EC.PrimitiveProperty {
222
- constructor(coreProperty: TCoreProperty, c: EC.Class) {
223
- super(coreProperty, c);
224
- }
225
- public override isPrimitive(): this is EC.PrimitiveProperty {
226
- return true;
227
- }
228
- public get extendedTypeName() {
229
- return this._coreProperty.extendedTypeName;
230
- }
231
- public get primitiveType() {
232
- switch (this._coreProperty.primitiveType) {
233
- case PrimitiveType.Binary:
234
- return "Binary";
235
- case PrimitiveType.Boolean:
236
- return "Boolean";
237
- case PrimitiveType.DateTime:
238
- return "DateTime";
239
- case PrimitiveType.Double:
240
- return "Double";
241
- case PrimitiveType.IGeometry:
242
- return "IGeometry";
243
- case PrimitiveType.Integer:
244
- return "Integer";
245
- case PrimitiveType.Long:
246
- return "Long";
247
- case PrimitiveType.Point2d:
248
- return "Point2d";
249
- case PrimitiveType.Point3d:
250
- return "Point3d";
251
- case PrimitiveType.String:
252
- return "String";
253
- }
254
- throw new Error("Primitive property is not initialized");
255
- }
256
- }
257
-
258
- class ECNavigationPropertyImpl extends ECPropertyImpl<CoreNavigationProperty> implements EC.NavigationProperty {
259
- constructor(coreProperty: CoreNavigationProperty, c: EC.Class) {
260
- super(coreProperty, c);
261
- }
262
- public override isNavigation(): this is EC.NavigationProperty {
263
- return true;
264
- }
265
- public get relationshipClass() {
266
- return createFromLazyLoaded(this._coreProperty.relationshipClass, (r) => new ECRelationshipClassImpl(r));
267
- }
268
- public get direction() {
269
- switch (this._coreProperty.direction) {
270
- case StrengthDirection.Backward:
271
- return "Backward";
272
- case StrengthDirection.Forward:
273
- return "Forward";
274
- }
275
- }
276
- }
277
-
278
- class ECEnumerationPropertyImpl<TCoreProperty extends CoreEnumerationProperty> extends ECPropertyImpl<TCoreProperty> implements EC.EnumerationProperty {
279
- constructor(coreProperty: TCoreProperty, c: EC.Class) {
280
- super(coreProperty, c);
281
- }
282
- public override isEnumeration(): this is EC.EnumerationProperty {
283
- return true;
284
- }
285
- public get enumeration() {
286
- return createFromOptionalLazyLoaded(this._coreProperty.enumeration, (coreEnumeration) => new ECEnumerationImpl(coreEnumeration));
287
- }
288
- public get extendedTypeName() {
289
- return this._coreProperty.extendedTypeName;
290
- }
291
- }
292
-
293
- class ECStructPropertyImpl<TCoreProperty extends CoreStructProperty> extends ECPropertyImpl<TCoreProperty> implements EC.StructProperty {
294
- constructor(coreProperty: TCoreProperty, c: EC.Class) {
295
- super(coreProperty, c);
296
- }
297
- public override isStruct(): this is EC.StructProperty {
298
- return true;
299
- }
300
- public get structClass(): EC.StructClass {
301
- return new ECStructClassImpl(this._coreProperty.structClass);
302
- }
303
- }
304
-
305
- class ECPrimitivesArrayPropertyImpl extends ECPrimitivePropertyImpl<CorePrimitiveArrayProperty> implements EC.PrimitiveArrayProperty {
306
- constructor(coreProperty: CorePrimitiveArrayProperty, c: EC.Class) {
307
- super(coreProperty, c);
308
- }
309
- public override isArray(): this is EC.ArrayProperty {
310
- return true;
311
- }
312
- public get minOccurs() {
313
- return this._coreProperty.minOccurs;
314
- }
315
- public get maxOccurs() {
316
- return this._coreProperty.maxOccurs;
317
- }
318
- }
319
-
320
- class ECEnumerationArrayPropertyImpl extends ECEnumerationPropertyImpl<CoreEnumerationArrayProperty> implements EC.EnumerationArrayProperty {
321
- constructor(coreProperty: CoreEnumerationArrayProperty, c: EC.Class) {
322
- super(coreProperty, c);
323
- }
324
- public override isArray(): this is EC.ArrayProperty {
325
- return true;
326
- }
327
- public get minOccurs() {
328
- return this._coreProperty.minOccurs;
329
- }
330
- public get maxOccurs() {
331
- return this._coreProperty.maxOccurs;
332
- }
333
- }
334
-
335
- class ECStructArrayPropertyImpl extends ECStructPropertyImpl<CoreStructArrayProperty> implements EC.StructArrayProperty {
336
- constructor(coreProperty: CoreStructArrayProperty, c: EC.Class) {
337
- super(coreProperty, c);
338
- }
339
- public override isArray(): this is EC.ArrayProperty {
340
- return true;
341
- }
342
- public get minOccurs() {
343
- return this._coreProperty.minOccurs;
344
- }
345
- public get maxOccurs() {
346
- return this._coreProperty.maxOccurs;
347
- }
348
- }
349
-
350
- async function createFromLazyLoaded<TSource extends CoreSchemaItem, TTarget>(
351
- source: LazyLoadedSchemaItem<TSource>,
352
- convert: (source: TSource) => TTarget,
353
- ): Promise<TTarget> {
354
- return source.then(convert);
355
- }
356
-
357
- async function createFromOptionalLazyLoaded<TSource extends CoreSchemaItem, TTarget>(
358
- source: LazyLoadedSchemaItem<TSource> | undefined,
359
- convert: (source: TSource) => TTarget,
360
- ): Promise<TTarget | undefined> {
361
- if (!source) {
362
- return undefined;
363
- }
364
- return source.then(convert);
365
- }
366
-
367
- class ECRelationshipConstraintImpl implements EC.RelationshipConstraint {
368
- constructor(
369
- private _coreConstraint: CoreRelationshipConstraint,
370
- private _schema: EC.Schema,
371
- ) {}
372
- public get multiplicity() {
373
- return this._coreConstraint.multiplicity
374
- ? {
375
- lowerLimit: this._coreConstraint.multiplicity.lowerLimit,
376
- upperLimit: this._coreConstraint.multiplicity.upperLimit,
377
- }
378
- : undefined;
379
- }
380
- public get polymorphic() {
381
- return this._coreConstraint.polymorphic ?? false;
382
- }
383
- public get abstractConstraint(): Promise<EC.EntityClass | EC.Mixin | EC.RelationshipClass | undefined> {
384
- return createFromOptionalLazyLoaded(this._coreConstraint.abstractConstraint, (coreConstraint) => createECClass(coreConstraint, this._schema));
385
- }
386
- }
387
-
388
- class ECKindOfQuantityImpl extends ECSchemaItemImpl<CoreKindOfQuantity> implements EC.KindOfQuantity {
389
- constructor(coreKindOfQuantity: CoreKindOfQuantity) {
390
- super(coreKindOfQuantity);
391
- }
392
- }
393
-
394
- class ECEnumerationImpl extends ECSchemaItemImpl<CoreEnumeration> implements EC.Enumeration {
395
- constructor(coreEnumeration: CoreEnumeration) {
396
- super(coreEnumeration);
397
- }
398
- public get enumerators() {
399
- return this._coreSchemaItem.enumerators.map((coreEnumerator) => ({ ...coreEnumerator }));
400
- }
401
- public get type() {
402
- switch (this._coreSchemaItem.type) {
403
- case PrimitiveType.String:
404
- return "String";
405
- case PrimitiveType.Integer:
406
- default:
407
- return "Number";
408
- }
409
- }
410
- public get isStrict() {
411
- return this._coreSchemaItem.isStrict;
412
- }
413
- }
@@ -1,122 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
-
6
- import { OrderedId64Iterable } from "@itwin/core-bentley";
7
- import { ECSqlReader, QueryBinder, QueryOptions, QueryOptionsBuilder, QueryRowFormat } from "@itwin/core-common";
8
- import { Point2d, Point3d } from "@itwin/core-geometry";
9
- import { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryReaderOptions, ECSqlQueryRow } from "@itwin/presentation-shared";
10
-
11
- /**
12
- * Defines input for `createECSqlQueryExecutor`. Generally, this is an instance of either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/)
13
- * or [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).
14
- */
15
- interface CoreECSqlReaderFactory {
16
- createQueryReader(ecsql: string, binder?: QueryBinder, options?: QueryOptions): ECSqlReader;
17
- }
18
-
19
- /**
20
- * Creates an `ECSqlQueryExecutor` from either [IModelDb](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/) or
21
- * [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/).
22
- *
23
- * Usage example:
24
- *
25
- * ```ts
26
- * import { IModelDb } from "@itwin/core-backend";
27
- * import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
28
- *
29
- * const imodel: IModelDb = getIModelDb();
30
- * const executor = createECSqlQueryExecutor(imodel);
31
- * for await (const row of executor.createQueryReader(MY_QUERY)) {
32
- * // TODO: do something with `row`
33
- * }
34
- * ```
35
- *
36
- * @beta
37
- */
38
- export function createECSqlQueryExecutor(imodel: CoreECSqlReaderFactory): ECSqlQueryExecutor {
39
- return {
40
- createQueryReader(query: ECSqlQueryDef, config?: ECSqlQueryReaderOptions) {
41
- const { ctes, ecsql, bindings } = query;
42
- const opts = new QueryOptionsBuilder();
43
- switch (config?.rowFormat) {
44
- case "ECSqlPropertyNames":
45
- opts.setRowFormat(QueryRowFormat.UseECSqlPropertyNames);
46
- break;
47
- case "Indexes":
48
- opts.setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes);
49
- break;
50
- }
51
- return new ECSqlQueryReaderImpl(
52
- imodel.createQueryReader(addCTEs(ecsql, ctes), bind(bindings ?? []), opts.getOptions()),
53
- config?.rowFormat === "Indexes" ? "array" : "object",
54
- );
55
- },
56
- };
57
- }
58
-
59
- class ECSqlQueryReaderImpl implements ReturnType<ECSqlQueryExecutor["createQueryReader"]> {
60
- public constructor(
61
- private _coreReader: ECSqlReader,
62
- private _format: "array" | "object",
63
- ) {}
64
- public [Symbol.asyncIterator](): AsyncIterableIterator<ECSqlQueryRow> {
65
- return this;
66
- }
67
- public async next(): Promise<IteratorResult<ECSqlQueryRow>> {
68
- const res = await this._coreReader.next();
69
- if (res.done) {
70
- return { done: true, value: undefined };
71
- }
72
- return {
73
- done: false,
74
- value: this._format === "array" ? res.value.toArray() : res.value.toRow(),
75
- };
76
- }
77
- }
78
-
79
- function bind(bindings: ECSqlBinding[]): QueryBinder {
80
- const binder = new QueryBinder();
81
- bindings.forEach((b, i) => {
82
- if (b.value === undefined) {
83
- binder.bindNull(i + 1);
84
- return;
85
- }
86
- switch (b.type) {
87
- case "boolean":
88
- binder.bindBoolean(i + 1, b.value);
89
- break;
90
- case "double":
91
- binder.bindDouble(i + 1, b.value);
92
- break;
93
- case "id":
94
- binder.bindId(i + 1, b.value);
95
- break;
96
- case "idset":
97
- binder.bindIdSet(i + 1, OrderedId64Iterable.sortArray(b.value));
98
- break;
99
- case "int":
100
- binder.bindInt(i + 1, b.value);
101
- break;
102
- case "long":
103
- binder.bindLong(i + 1, b.value);
104
- break;
105
- case "point2d":
106
- binder.bindPoint2d(i + 1, Point2d.fromJSON(b.value));
107
- break;
108
- case "point3d":
109
- binder.bindPoint3d(i + 1, Point3d.fromJSON(b.value));
110
- break;
111
- case "string":
112
- binder.bindString(i + 1, b.value);
113
- break;
114
- }
115
- });
116
- return binder;
117
- }
118
-
119
- function addCTEs(ecsql: string, ctes: string[] | undefined) {
120
- const ctesPrefix = ctes?.length ? `WITH RECURSIVE ${ctes.join(", ")} ` : "";
121
- return `${ctesPrefix}${ecsql}`;
122
- }
@@ -1,92 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
-
6
- import { Event } from "@itwin/presentation-shared";
7
-
8
- /**
9
- * An interface for a transaction manager that has 3 types of events fired before and after a commit
10
- * and when changes are applied on a briefcase.
11
- *
12
- * Generally, this either means [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed
13
- * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns), or
14
- * [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed
15
- * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).
16
- */
17
- interface ICoreTxnManager {
18
- /**
19
- * Event raised before a commit operation is performed. Initiated by a call to either
20
- * [IModelDb.saveChanges](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/savechanges/)
21
- * or [BriefcaseConnection.saveChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/savechanges/),
22
- * unless there are no changes to save.
23
- */
24
- onCommit: Event;
25
- /**
26
- * Event raised after a commit operation is performed. Initiated by a call to either
27
- * [IModelDb.saveChanges](https://www.itwinjs.org/reference/core-backend/imodels/imodeldb/savechanges/)
28
- * or [BriefcaseConnection.saveChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/savechanges/),
29
- * even if there were no changes to save.
30
- */
31
- onCommitted: Event;
32
- /**
33
- * Event raised after a changeset has been applied to the briefcase. Changesets may be applied as a result of
34
- * [BriefcaseDb.pullChanges](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/) or
35
- * [BriefcaseConnection.pullChanges](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/pullchanges/),
36
- * or by undo/redo operations.
37
- */
38
- onChangesApplied: Event;
39
- }
40
-
41
- /**
42
- * Registers listeners to `txns` events and calls provided `onChanged` callback when transaction manager
43
- * reports there are iModel data changes.
44
- *
45
- * Usage example:
46
- *
47
- * ```ts
48
- * import { BriefcaseDb } from "@itwin/core-backend";
49
- * import { registerTxnListeners } from "@itwin/presentation-core-interop";
50
- * import { HierarchyProvider } from "@itwin/presentation-hierarchies";
51
- *
52
- * // get iModel and hierarchy provider from arbitrary sources
53
- * const db: BriefcaseDb = getIModel();
54
- * const provider: HierarchyProvider = getHierarchyProvider();
55
- *
56
- * // register the listeners
57
- * const unregister = registerTxnListeners(db.txns, () => {
58
- * // notify provided about the changed data
59
- * provider.notifyDataSourceChanged();
60
- * // TODO: force the components using `provider` to reload
61
- * });
62
- *
63
- * // clean up on iModel close
64
- * db.onClosed.addOnce(() => unregister());
65
- * ```
66
- *
67
- * @param txns Either [TxnManager](https://www.itwinjs.org/reference/core-backend/imodels/txnmanager/), accessed
68
- * through [BriefcaseDb.txns](https://www.itwinjs.org/reference/core-backend/imodels/briefcasedb/#txns),
69
- * or [BriefcaseTxns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcasetxns/), accessed
70
- * through [BriefcaseConnection.txns](https://www.itwinjs.org/reference/core-frontend/imodelconnection/briefcaseconnection/#txns).
71
- * @param onChanged A function to call when transaction manager reports iModel data changes.
72
- * @returns A function that unregisters the transaction manager listeners.
73
- * @beta
74
- */
75
- export function registerTxnListeners(txns: ICoreTxnManager, onChanged: () => void): () => void {
76
- let hasChanges = false;
77
- const beforeCommit = txns.onCommit.addListener(() => {
78
- hasChanges = true;
79
- });
80
- const afterCommit = txns.onCommitted.addListener(() => {
81
- if (hasChanges) {
82
- onChanged();
83
- }
84
- hasChanges = false;
85
- });
86
- const appliedChanges = txns.onChangesApplied.addListener(onChanged);
87
- return () => {
88
- beforeCommit();
89
- afterCommit();
90
- appliedChanges();
91
- };
92
- }
@@ -1,10 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
-
6
- export { createValueFormatter } from "./core-interop/Formatting";
7
- export { createLogger } from "./core-interop/Logging";
8
- export { createECSchemaProvider } from "./core-interop/Metadata";
9
- export { createECSqlQueryExecutor } from "./core-interop/QueryExecutor";
10
- export { registerTxnListeners } from "./core-interop/Transactions";