Skip to content

Commit

Permalink
Fix ALL lint errors and remove deprecated danglingPredecessorsBehavior (
Browse files Browse the repository at this point in the history
  • Loading branch information
nick4598 authored Apr 15, 2024
1 parent 336227e commit e86ddcb
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 50 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = [
}
},
{
files: ["packages/transformer/test/**/*.ts"],
files: ["packages/transformer/src/test/**/*.ts"],
rules: {
"@itwin/no-internal-barrel-imports": "off"
}
Expand Down
1 change: 1 addition & 0 deletions packages/transformer/src/EntityUnifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
ConcreteEntity,
ConcreteEntityProps,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
EntityReferences,
Expand Down
2 changes: 1 addition & 1 deletion packages/transformer/src/IModelCloneContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import {
RelatedElementProps,
} from "@itwin/core-common";
import {
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
EntityReferences,
IModelElementCloneContext,
IModelJsNative,
SQLiteDb,
} from "@itwin/core-backend";
import { ECReferenceTypesCache } from "./ECReferenceTypesCache";
import { EntityUnifier } from "./EntityUnifier";
Expand Down
2 changes: 1 addition & 1 deletion packages/transformer/src/IModelExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ChangesetECAdaptor,
DefinitionModel,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
ElementMultiAspect,
Expand All @@ -32,7 +33,6 @@ import {
import {
AccessToken,
assert,
CompressedId64Set,
DbResult,
Id64String,
IModelStatus,
Expand Down
12 changes: 4 additions & 8 deletions packages/transformer/src/IModelImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @module iModels
*/
import {
CompressedId64Set,
Guid,
Id64,
Id64String,
Expand Down Expand Up @@ -38,10 +37,7 @@ import {
SourceAndTarget,
SubCategory,
} from "@itwin/core-backend";
import type {
IModelTransformOptions,
RelationshipPropsForDelete,
} from "./IModelTransformer";
import type { RelationshipPropsForDelete } from "./IModelTransformer";
import * as assert from "assert";
import { deleteElementTreeCascade } from "./ElementCascadingDeleter";

Expand Down Expand Up @@ -113,7 +109,7 @@ export class IModelImporter {
public readonly doNotUpdateElementIds = new Set<Id64String>([]);

/** This set is ONLY used for elements that are always present even in an "empty" iModel. We will use this set to filter out changes to root elements if [[IModelTransformOptions.skipPropagateChangesToRootElements]] is false. */
private readonly rootElementIds = new Set<Id64String>([
private readonly _rootElementIds = new Set<Id64String>([
IModel.rootSubjectId,
IModel.dictionaryId,
IModelImporter._realityDataSourceLinkPartitionStaticId,
Expand Down Expand Up @@ -151,7 +147,7 @@ export class IModelImporter {
private doNotUpdateElement(elementId: Id64String): boolean {
if (
this.options.skipPropagateChangesToRootElements &&
this.rootElementIds.has(elementId)
this._rootElementIds.has(elementId)
)
return true;
if (this.doNotUpdateElementIds.has(elementId)) return true;
Expand Down Expand Up @@ -256,7 +252,7 @@ export class IModelImporter {
// Otherwise we always insert during a preserveElementIdsForFiltering operation
if (
(isSubCategory(elementProps) && isDefaultSubCategory(elementProps)) ||
this.rootElementIds.has(elementProps.id)
this._rootElementIds.has(elementProps.id)
) {
this.onUpdateElement(elementProps);
} else {
Expand Down
28 changes: 6 additions & 22 deletions packages/transformer/src/IModelTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as nodeAssert from "assert";
import {
AccessToken,
assert,
CompressedId64Set,
DbResult,
Guid,
GuidString,
Expand All @@ -21,7 +20,6 @@ import {
IModelStatus,
Logger,
MarkRequired,
OpenMode,
YieldManager,
} from "@itwin/core-bentley";
import * as ECSchemaMetaData from "@itwin/ecschema-metadata";
Expand All @@ -38,6 +36,7 @@ import {
DefinitionPartition,
ECSchemaXmlContext,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
ElementMultiAspect,
Expand Down Expand Up @@ -65,7 +64,6 @@ import {
Schema,
SqliteChangeOp,
SqliteChangesetReader,
SQLiteDb,
Subject,
SynchronizationConfigLink,
} from "@itwin/core-backend";
Expand Down Expand Up @@ -195,21 +193,6 @@ export interface IModelTransformOptions {
*/
preserveElementIdsForFiltering?: boolean;

/** The behavior to use when an element reference (id) is found stored as a reference on an element in the source,
* but the referenced element does not actually exist in the source.
* It is possible to craft an iModel with dangling references/invalidated relationships by, e.g., deleting certain
* elements without fixing up references.
*
* @note "reject" will throw an error and reject the transformation upon finding this case.
* @note "ignore" passes the issue down to consuming applications, iModels that have invalid element references
* like this can cause errors, and you should consider adding custom logic in your transformer to remove the
* reference depending on your use case.
* @default "reject"
* @beta
* @deprecated in 3.x. use [[danglingReferencesBehavior]] instead, the use of the term *predecessors* was confusing and became inaccurate when the transformer could handle cycles
*/
danglingPredecessorsBehavior?: "reject" | "ignore";

/** The behavior to use when an element reference (id) is found stored as a reference on an element in the source,
* but the referenced element does not actually exist in the source.
* It is possible to craft an iModel with dangling references/invalidated relationships by, e.g., deleting certain
Expand Down Expand Up @@ -655,9 +638,7 @@ export class IModelTransformer extends IModelExportHandler {
options?.targetScopeElementId ?? IModel.rootSubjectId,
// eslint-disable-next-line deprecation/deprecation
danglingReferencesBehavior:
options?.danglingReferencesBehavior ??
options?.danglingPredecessorsBehavior ??
"reject",
options?.danglingReferencesBehavior ?? "reject",
branchRelationshipDataBehavior:
options?.branchRelationshipDataBehavior ?? "reject",
};
Expand Down Expand Up @@ -794,6 +775,7 @@ export class IModelTransformer extends IModelExportHandler {
);
Logger.logInfo(
loggerCategory,
// eslint-disable-next-line deprecation/deprecation
`this._isReverseSynchronization=${this._options.isReverseSynchronization}`
);
Logger.logInfo(
Expand Down Expand Up @@ -1998,7 +1980,7 @@ export class IModelTransformer extends IModelExportHandler {
// there can only be one repositoryModel per database, so ignore the repo model on remapped subjects
const isRemappedRootSubject =
sourceModel.id === IModel.repositoryModelId &&
targetModeledElementId != sourceModel.id;
targetModeledElementId !== sourceModel.id;
if (isRemappedRootSubject) return;
const targetModelProps: ModelProps = this.onTransformModel(
sourceModel,
Expand Down Expand Up @@ -3207,7 +3189,9 @@ export class IModelTransformer extends IModelExportHandler {
this._options.forceExternalSourceAspectProvenance &&
this.shouldDetectDeletes()
) {
// eslint-disable-next-line deprecation/deprecation
await this.detectElementDeletes();
// eslint-disable-next-line deprecation/deprecation
await this.detectRelationshipDeletes();
}

Expand Down
1 change: 1 addition & 0 deletions packages/transformer/src/test/IModelTransformerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
DrawingCategory,
DrawingGraphicRepresentsElement,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
ElementMultiAspect,
Expand Down
2 changes: 1 addition & 1 deletion packages/transformer/src/test/TestUtils/AdvancedEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare global {

/** get whether two numbers are almost equal within a tolerance */
const isAlmostEqualNumber: (a: number, b: number, tol: number) => boolean =
Geometry.isSameCoordinate;
Geometry.isSameCoordinate.bind(Geometry);

/** normalize a classname for comparisons */
const normalizeClassName = (name: string) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/transformer/src/test/TestUtils/IModelTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import {
DrawingModel,
DrawingViewDefinition,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementAspect,
ElementDrivesElement,
Expand Down Expand Up @@ -1267,6 +1268,7 @@ export class IModelTestUtils {
}

public static count(
this: void,
iModelDb: IModelDb,
classFullName: string,
whereClause?: string
Expand Down
10 changes: 7 additions & 3 deletions packages/transformer/src/test/TestUtils/TimelineTestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import {
import { IModelTestUtils } from "./IModelTestUtils";
import { omit } from "@itwin/core-bentley";

const { saveAndPushChanges } = IModelTestUtils;
const saveAndPushChanges = async (
accessToken: string,
briefcase: BriefcaseDb,
description: string
) => IModelTestUtils.saveAndPushChanges(accessToken, briefcase, description);

export const deleted = Symbol("DELETED");

Expand Down Expand Up @@ -494,7 +498,7 @@ export async function runTimeline(
since: startIndex,
initTransformer,
expectThrow,
assert,
assert: assertFxns,
finalizeTransformationOptions,
},
] = getSync(event)!;
Expand Down Expand Up @@ -522,7 +526,7 @@ export async function runTimeline(
expectThrow === false || expectThrow === undefined,
"expectThrow was set to true and transformer succeeded."
).to.be.true;
assert?.afterProcessChanges?.(syncer);
assertFxns?.afterProcessChanges?.(syncer);
} catch (err: any) {
if (/startChangesetId should be exactly/.test(err.message)) {
console.log("change history:"); // eslint-disable-line
Expand Down
1 change: 1 addition & 0 deletions packages/transformer/src/test/standalone/Catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DrawingGraphic,
DrawingModel,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementOwnsChildElements,
EntityClassType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import {
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementRefersToElements,
GeometryPart,
Expand All @@ -27,8 +28,7 @@ import {
import { Point3d, YawPitchRollAngles } from "@itwin/core-geometry";
import { assert, expect } from "chai";
import * as path from "path";
import { IModelExportHandler } from "../../IModelExporter";
import { IModelExporter } from "../../IModelExporter";
import { IModelExporter, IModelExportHandler } from "../../IModelExporter";
import { IModelTransformerTestUtils } from "../IModelTransformerUtils";
import { createBRepDataProps } from "../TestUtils/GeometryTestUtil";
import { KnownTestLocations } from "../TestUtils/KnownTestLocations";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DrawingGraphic,
DrawingModel,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementMultiAspect,
ElementOwnsChildElements,
Expand Down Expand Up @@ -55,6 +56,7 @@ import {
} from "@itwin/core-backend";
import * as coreBackendPkgJson from "@itwin/core-backend/package.json";
import * as ECSchemaMetaData from "@itwin/ecschema-metadata";

import * as TestUtils from "../TestUtils";
import {
DbResult,
Expand Down Expand Up @@ -310,6 +312,7 @@ describe("IModelTransformer", () => {
targetDb,
ElementRefersToElements.classFullName
);
assert.isAtLeast(numTargetElements, 1);
assert.isAtLeast(numTargetUniqueAspects, 1);
assert.isAtLeast(numTargetMultiAspects, 1);
assert.isAtLeast(numTargetRelationships, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
deleteElementTree,
DisplayStyle3d,
ECSqlStatement,
// eslint-disable-next-line @typescript-eslint/no-redeclare
Element,
ElementGroupsMembers,
ElementOwnsChildElements,
Expand Down Expand Up @@ -68,7 +69,6 @@ import {
ModelProps,
PhysicalElementProps,
Placement3d,
RootSubjectProps,
SpatialViewDefinitionProps,
SubCategoryAppearance,
SubjectProps,
Expand All @@ -79,7 +79,6 @@ import {
IModelExporter,
IModelImporter,
IModelTransformer,
TargetScopeProvenanceJsonProps,
TransformerLoggerCategory,
} from "../../transformer";
import {
Expand Down Expand Up @@ -127,6 +126,7 @@ describe("IModelTransformerHub", () => {
accessToken = await HubWrappers.getAccessToken(
TestUtils.TestUserType.Regular
);

saveAndPushChanges = IModelTestUtils.saveAndPushChanges.bind(
IModelTestUtils,
accessToken
Expand Down Expand Up @@ -1990,10 +1990,7 @@ describe("IModelTransformerHub", () => {
seedDb.saveChanges();
seedDb.close();

let sourceIModelId: string | undefined;
let targetIModelId: string | undefined;

sourceIModelId = await IModelHost.hubAccess.createNewIModel({
const sourceIModelId = await IModelHost.hubAccess.createNewIModel({
iTwinId,
iModelName: "TransformerSource",
description: "source",
Expand All @@ -2012,7 +2009,7 @@ describe("IModelTransformerHub", () => {
sourceDb.performCheckpoint(); // so we can use as a seed

// forking target
targetIModelId = await IModelHost.hubAccess.createNewIModel({
const targetIModelId = await IModelHost.hubAccess.createNewIModel({
iTwinId,
iModelName: "TransformerTarget",
description: "target",
Expand Down Expand Up @@ -3762,9 +3759,7 @@ describe("IModelTransformerHub", () => {

// Update Elements now.
const rootSubjectFromBranch =
branch.elements.getElementProps<SubjectProps>(
"0x1"
) as SubjectProps;
branch.elements.getElementProps<SubjectProps>("0x1");
branch.elements.updateElement({
...rootSubjectFromBranch,
description: "test description",
Expand Down
2 changes: 1 addition & 1 deletion packages/transformer/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import * as semver from "semver";
import { version as iTwinCoreBackendVersion } from "@itwin/core-backend/package.json";

// must use an untyped require to not hoist src into lib/cjs, also the compiled output will be in 'lib/cjs', not 'src' so use `../..` to reach package.json
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {
version: ourVersion,
name: ourName,
peerDependencies,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require("../../package.json");

const ourITwinCoreBackendDepRange = peerDependencies["@itwin/core-backend"];
Expand Down

0 comments on commit e86ddcb

Please sign in to comment.