Skip to content

Commit

Permalink
Make processALl and processChanges private, expose a public process f…
Browse files Browse the repository at this point in the history
…unction and let people pass isSync to constructor of imodeltransformer (#190)

Co-authored-by: Daniel Erbynn <Daniel.Erbynn@bentley.com>
Co-authored-by: derbynn <44528840+derbynn@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent 7131a96 commit f4e5a04
Show file tree
Hide file tree
Showing 17 changed files with 5,695 additions and 4,575 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Make processAll and processChanges private, expose a public process function and let people pass isSync to constructor of imodeltransformer",
"packageName": "@itwin/imodel-transformer",
"email": "22119573+nick4598@users.noreply.github.com",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions packages/performance-tests/test/rawInserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default async function rawInserts(
});

const [transformWithProvTimer] = await timed(async () => {
await transformerWithProv.processAll();
await transformerWithProv.process();
});

reporter.addEntry(
Expand Down Expand Up @@ -157,7 +157,7 @@ export default async function rawInserts(
});

const [transformNoProvTimer] = await timed(async () => {
await transformerNoProv.processAll();
await transformerNoProv.process();
});

reporter.addEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const nativeTransformerTestModule: TestTransformerModule = {
return {
async run() {
await transformer.processSchemas();
await transformer.processAll();
await transformer.process();
transformer.dispose();
},
};
Expand Down Expand Up @@ -96,7 +96,7 @@ const nativeTransformerTestModule: TestTransformerModule = {
});
return {
async run() {
await transformer.processAll();
await transformer.process();
transformer.dispose();
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/test-app/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ void (async () => {
if (processChanges) {
assert(undefined !== args.sourceStartChangesetId);
await Transformer.transformChanges(
await acquireAccessToken(),
sourceDb,
targetDb,
args.sourceStartChangesetId,
Expand Down
16 changes: 8 additions & 8 deletions packages/test-app/src/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import {
AccessToken,
assert,
DbResult,
Id64,
Expand Down Expand Up @@ -70,7 +69,7 @@ export class Transformer extends IModelTransformer {
const transformer = new Transformer(sourceDb, targetDb, options);
await transformer.processSchemas();
await transformer.saveChanges("processSchemas");
await transformer.processAll();
await transformer.process();
await transformer.saveChanges("processAll");
if (options?.deleteUnusedGeometryParts) {
transformer.deleteUnusedGeometryParts();
Expand All @@ -81,7 +80,6 @@ export class Transformer extends IModelTransformer {
}

public static async transformChanges(
accessToken: AccessToken,
sourceDb: IModelDb,
targetDb: IModelDb,
sourceStartChangesetId: string,
Expand All @@ -91,13 +89,15 @@ export class Transformer extends IModelTransformer {
assert("" === sourceStartChangesetId);
return this.transformAll(sourceDb, targetDb, options);
}
const transformer = new Transformer(sourceDb, targetDb, options);
const transformer = new Transformer(sourceDb, targetDb, {
...options,
argsForProcessChanges: {
startChangeset: { id: sourceStartChangesetId },
},
});
await transformer.processSchemas();
await transformer.saveChanges("processSchemas");
await transformer.processChanges({
accessToken,
startChangeset: { id: sourceStartChangesetId },
});
await transformer.process();
await transformer.saveChanges("processChanges");
if (options?.deleteUnusedGeometryParts) {
transformer.deleteUnusedGeometryParts();
Expand Down
52 changes: 23 additions & 29 deletions packages/transformer/src/IModelExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
} from "@itwin/ecschema-metadata";
import { TransformerLoggerCategory } from "./TransformerLoggerCategory";
import * as nodeAssert from "assert";
import type { InitOptions } from "./IModelTransformer";
import {
ElementAspectsHandler,
ExportElementAspectsStrategy,
Expand Down Expand Up @@ -83,34 +82,34 @@ export type ExporterInitOptions = ExportChangesOptions;
* Arguments for [[IModelExporter.exportChanges]]
* @public
*/
export type ExportChangesOptions = Omit<InitOptions, "startChangeset"> & {
export type ExportChangesOptions = {
skipPropagateChangesToRootElements?: boolean;
} /**
* an array of ChangesetFileProps which are used to read the changesets and populate the ChangedInstanceIds using [[ChangedInstanceIds.initialize]] in [[IModelExporter.exportChanges]]
* @note mutually exclusive with @see changesetRanges, @see startChangeset and @see changedInstanceIds, so define one of the four, never more
*/ & (
| { csFileProps: ChangesetFileProps[] }
/**
* Class instance that contains modified elements between 2 versions of an iModel.
* If this parameter is not provided, then [[ChangedInstanceIds.initialize]] in [[IModelExporter.exportChanges]]
* will be called to discover changed elements.
* @note mutually exclusive with @see changesetRanges, @see csFileProps and @see startChangeset, so define one of the four, never more
*/
| { changedInstanceIds: ChangedInstanceIds }
/**
* An ordered array of changeset index ranges, e.g. [[2,2], [4,5]] is [2,4,5]
* @note mutually exclusive with @see changedInstanceIds, @see csFileProps and @see startChangeset, so define one of the four, never more
*/
| { changesetRanges: [number, number][] }
/**
* Include changes from this changeset up through and including the current changeset.
* @note To form a range of versions to process, set `startChangeset` for the start (inclusive)
* of the desired range and open the source iModel as of the end (inclusive) of the desired range.
* @default the current changeset of the sourceDb, if undefined
*/
| { startChangeset: { id?: string; index?: number } }
| {}
);
| { csFileProps: ChangesetFileProps[] }
/**
* Class instance that contains modified elements between 2 versions of an iModel.
* If this parameter is not provided, then [[ChangedInstanceIds.initialize]] in [[IModelExporter.exportChanges]]
* will be called to discover changed elements.
* @note mutually exclusive with @see changesetRanges, @see csFileProps and @see startChangeset, so define one of the four, never more
*/
| { changedInstanceIds: ChangedInstanceIds }
/**
* An ordered array of changeset index ranges, e.g. [[2,2], [4,5]] is [2,4,5]
* @note mutually exclusive with @see changedInstanceIds, @see csFileProps and @see startChangeset, so define one of the four, never more
*/
| { changesetRanges: [number, number][] }
/**
* Include changes from this changeset up through and including the current changeset.
* @note To form a range of versions to process, set `startChangeset` for the start (inclusive)
* of the desired range and open the source iModel as of the end (inclusive) of the desired range.
* @default the current changeset of the sourceDb, if undefined
*/
| { startChangeset: { id?: string; index?: number } }
| {}
);

/** Handles the events generated by IModelExporter.
* @note Change information is available when `IModelExportHandler` methods are invoked via [IModelExporter.exportChanges]($transformer), but not available when invoked via [IModelExporter.exportAll]($transformer).
Expand Down Expand Up @@ -452,7 +451,6 @@ export class IModelExporter {
typeof accessTokenOrOpts === "object"
? accessTokenOrOpts
: {
accessToken: accessTokenOrOpts,
startChangeset: { id: startChangesetId },
};

Expand Down Expand Up @@ -1190,7 +1188,6 @@ export class ChangedInstanceIds {
if ("changedInstanceIds" in opts) return opts.changedInstanceIds;

const iModelId = opts.iModel.iModelId;
const accessToken = opts.accessToken;

const startChangeset =
"startChangeset" in opts ? opts.startChangeset : undefined;
Expand All @@ -1205,15 +1202,13 @@ export class ChangedInstanceIds {
changeset: {
id: startChangeset.id ?? opts.iModel.changeset.id,
},
accessToken,
})
).index,
opts.iModel.changeset.index ??
(
await IModelHost.hubAccess.queryChangeset({
iModelId,
changeset: { id: opts.iModel.changeset.id },
accessToken,
})
).index,
],
Expand All @@ -1227,7 +1222,6 @@ export class ChangedInstanceIds {
await Promise.all(
changesetRanges.map(async ([first, end]) =>
IModelHost.hubAccess.downloadChangesets({
accessToken,
iModelId,
range: { first, end },
targetDir: BriefcaseManager.getChangeSetsPath(iModelId),
Expand Down
4 changes: 2 additions & 2 deletions packages/transformer/src/IModelImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ export class IModelImporter {
protected onProgress(): void {}

/** Optionally compute the projectExtents for the target iModel depending on the options for this IModelImporter.
* @note This method is automatically called from [IModelTransformer.processChanges]($transformer) and [IModelTransformer.processAll]($transformer).
* @note This method is automatically called from [IModelTransformer.process]($transformer).
* @see [IModelDb.computeProjectExtents]($backend), [[autoExtendProjectExtents]]
*/
public computeProjectExtents(): void {
Expand Down Expand Up @@ -755,7 +755,7 @@ export class IModelImporter {
}

/** Examine the geometry streams of every [GeometricElement3d]($backend) in the target iModel and apply the specified optimizations.
* @note This method is automatically called from [[IModelTransformer.processChanges]] and [[IModelTransformer.processAll]] if
* @note This method is automatically called from [[IModelTransformer.process]] if
* [[IModelTransformOptions.optimizeGeometry]] is defined.
*/
public optimizeGeometry(options: OptimizeGeometryOptions): void {
Expand Down
Loading

0 comments on commit f4e5a04

Please sign in to comment.