UNPKG

@itwin/core-frontend

Version:
82 lines 2.88 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module IModelConnection */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityChanges = exports.Metadata = void 0; const core_bentley_1 = require("@itwin/core-bentley"); class Metadata { classFullName; baseClasses = []; constructor(name) { this.classFullName = name; } is(baseName) { return baseName === this.classFullName || this.baseClasses.some((base) => base.is(baseName)); } } exports.Metadata = Metadata; function* entityChangesIterator(changes, options) { let excludedMetaIndices; if (options?.includeMetadata) { for (let i = 0; i < changes.metadata.length; i++) { if (!options.includeMetadata(changes.metadata[i])) { excludedMetaIndices = excludedMetaIndices ?? new Set(); excludedMetaIndices.add(i); } } } function* process(type) { if (options?.includeTypes && !options.includeTypes.includes(type)) { return; } const ids = changes[type]; if (undefined === ids) { return; } const metaIndices = changes.args[`${type}Meta`]; let index = 0; for (const id of core_bentley_1.CompressedId64Set.iterable(ids)) { const metaIndex = metaIndices[index++]; if (excludedMetaIndices && excludedMetaIndices.has(metaIndex)) { continue; } const metadata = changes.metadata[metaIndex]; yield { type, id, metadata }; } } yield* process("inserted"); yield* process("deleted"); yield* process("updated"); } class EntityChanges { args; metadata; constructor(args) { this.args = args; this.metadata = args.meta.map((x) => new Metadata(x.name)); for (let i = 0; i < this.metadata.length; i++) { const meta = this.metadata[i]; for (const baseIndex of args.meta[i].bases) { meta.baseClasses.push(this.metadata[baseIndex]); } } } get inserted() { return this.args.inserted; } get deleted() { return this.args.deleted; } get updated() { return this.args.updated; } [Symbol.iterator]() { return entityChangesIterator(this); } filter(options) { return { [Symbol.iterator]: () => entityChangesIterator(this, options), }; } } exports.EntityChanges = EntityChanges; //# sourceMappingURL=TxnEntityChanges.js.map