@itwin/core-backend
Version:
iTwin.js backend components
177 lines • 11.7 kB
TypeScript
import { AccessToken, BeEvent, GuidString, Id64String, OpenMode } from "@itwin/core-bentley";
import { ChangesetIdWithIndex, Code, CodeProps, ColorDef, GeometryStreamProps, IModelVersionProps, LocalFileName, PhysicalElementProps, RelatedElement, RequestNewBriefcaseProps } from "@itwin/core-common";
import { Point2d, Point3d } from "@itwin/core-geometry";
import { RequestNewBriefcaseArg } from "../BriefcaseManager";
import { CheckpointProps, DownloadRequest } from "../CheckpointManager";
import { BriefcaseDb, Element, IModelDb, Model, SnapshotDb } from "../core-backend";
import { PhysicalElement, Subject } from "../Element";
import { ElementDrivesElement, RelationshipProps } from "../Relationship";
import { Schema } from "../Schema";
import { HubMock } from "../internal/HubMock";
import { BackendHubAccess } from "../BackendHubAccess";
export interface IModelTestUtilsOpenOptions {
copyFilename?: string;
enableTransactions?: boolean;
openMode?: OpenMode;
}
export declare class TestBim extends Schema {
static get schemaName(): string;
}
export interface TestRelationshipProps extends RelationshipProps {
property1: string;
}
export declare class TestElementDrivesElement extends ElementDrivesElement {
static get className(): string;
property1: string;
static rootChanged: BeEvent<(props: RelationshipProps, imodel: IModelDb) => void>;
static deletedDependency: BeEvent<(props: RelationshipProps, imodel: IModelDb) => void>;
static onRootChanged(props: RelationshipProps, imodel: IModelDb): void;
static onDeletedDependency(props: RelationshipProps, imodel: IModelDb): void;
}
export interface TestPhysicalObjectProps extends PhysicalElementProps {
intProperty: number;
}
export declare class TestPhysicalObject extends PhysicalElement {
static get className(): string;
intProperty: number;
static beforeOutputsHandled: BeEvent<(id: Id64String, imodel: IModelDb) => void>;
static allInputsHandled: BeEvent<(id: Id64String, imodel: IModelDb) => void>;
static onBeforeOutputsHandled(id: Id64String, imodel: IModelDb): void;
static onAllInputsHandled(id: Id64String, imodel: IModelDb): void;
}
/** the types of users available for tests */
export declare enum TestUserType {
Regular = 0,
Manager = 1,
Super = 2,
SuperManager = 3
}
/** A wrapper around the BackendHubAccess API through IModelHost[_hubAccess].
*
* All methods in this class should be usable with any BackendHubAccess implementation (i.e. HubMock and IModelHubBackend).
*/
export declare class HubWrappers {
protected static get hubMock(): typeof HubMock;
static getAccessToken(user: TestUserType): Promise<string>;
/** Create an iModel with the name provided if it does not already exist. If it does exist, the iModelId is returned. */
static createIModel(accessToken: AccessToken, iTwinId: GuidString, iModelName: string): Promise<GuidString>;
/** Deletes and re-creates an iModel with the provided name in the iTwin.
* @returns the iModelId of the newly created iModel.
*/
static recreateIModel(...[arg]: Parameters<BackendHubAccess["createNewIModel"]>): Promise<GuidString>;
/** Delete an IModel from the hub */
static deleteIModel(accessToken: AccessToken, iTwinId: string, iModelName: string): Promise<void>;
/** Push an iModel to the Hub */
static pushIModel(accessToken: AccessToken, iTwinId: string, pathname: string, iModelName?: string, overwrite?: boolean): Promise<GuidString>;
/** Helper to open a briefcase db directly with the BriefcaseManager API */
static downloadAndOpenBriefcase(args: RequestNewBriefcaseArg & {
noLock?: true;
}): Promise<BriefcaseDb>;
/** Opens the specific iModel as a Briefcase through the same workflow the IModelReadRpc.getConnectionProps method will use. Replicates the way a frontend would open the iModel. */
static openBriefcaseUsingRpc(args: RequestNewBriefcaseProps & {
accessToken: AccessToken;
deleteFirst?: boolean;
}): Promise<BriefcaseDb>;
/** Downloads a checkpoint and opens it as a SnapShotDb */
static downloadAndOpenCheckpoint(args: {
accessToken: AccessToken;
iTwinId: GuidString;
iModelId: GuidString;
asOf?: IModelVersionProps;
}): Promise<SnapshotDb>;
/** Opens the specific Checkpoint iModel, `SyncMode.FixedVersion`, through the same workflow the IModelReadRpc.getConnectionProps method will use. Replicates the way a frontend would open the iModel. */
static openCheckpointUsingRpc(args: RequestNewBriefcaseProps & {
accessToken: AccessToken;
deleteFirst?: boolean;
}): Promise<IModelDb>;
/**
* Purges all acquired briefcases for the specified iModel (and user), if the specified threshold of acquired briefcases is exceeded
*/
static purgeAcquiredBriefcasesById(accessToken: AccessToken, iModelId: GuidString, onReachThreshold?: () => void, acquireThreshold?: number): Promise<void>;
static closeAndDeleteBriefcaseDb(accessToken: AccessToken, briefcaseDb: IModelDb): Promise<void>;
}
export declare class IModelTestUtils {
protected static get knownTestLocations(): {
outputDir: string;
assetsDir: string;
};
/** Generate a name for an iModel that's unique using the baseName provided and appending a new GUID. */
static generateUniqueName(baseName: string): string;
static openCheckpoint(fileName: LocalFileName, checkpoint: CheckpointProps): SnapshotDb;
/** try to open an existing local file to satisfy a download request */
static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined;
/** Prepare for an output file by:
* - Resolving the output file name under the known test output directory
* - Making directories as necessary
* - Removing a previous copy of the output file
* @param subDirName Sub-directory under known test output directory. Should match the name of the test file minus the .test.ts file extension.
* @param fileName Name of output fille
*/
static prepareOutputFile(subDirName: string, fileName: string): LocalFileName;
/** Resolve an asset file path from the asset name by looking in the known assets directory */
static resolveAssetFile(assetName: string): LocalFileName;
static resolveFontFile(fontName: string): LocalFileName;
/** Orchestrates the steps necessary to create a new snapshot iModel from a seed file. */
static createSnapshotFromSeed(testFileName: string, seedFileName: LocalFileName): SnapshotDb;
static getUniqueModelCode(testDb: IModelDb, newModelCodeBase: string): Code;
static generateChangeSetId(): ChangesetIdWithIndex;
/** Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel. */
static createAndInsertPhysicalPartition(testDb: IModelDb, newModelCode: CodeProps, parentId?: Id64String): Id64String;
/** Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel. */
static createAndInsertPhysicalPartitionAsync(testDb: IModelDb, newModelCode: CodeProps, parentId?: Id64String): Promise<Id64String>;
/** Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel. */
static createAndInsertPhysicalModel(testDb: IModelDb, modeledElementRef: RelatedElement, privateModel?: boolean): Id64String;
/** Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel. */
static createAndInsertPhysicalModelAsync(testDb: IModelDb, modeledElementRef: RelatedElement, privateModel?: boolean): Promise<Id64String>;
/**
* Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel.
* @return [modeledElementId, modelId]
*/
static createAndInsertPhysicalPartitionAndModel(testImodel: IModelDb, newModelCode: CodeProps, privateModel?: boolean, parent?: Id64String): Id64String[];
/**
* Create and insert a PhysicalPartition element (in the repositoryModel) and an associated PhysicalModel.
* @return [modeledElementId, modelId]
*/
static createAndInsertPhysicalPartitionAndModelAsync(testImodel: IModelDb, newModelCode: CodeProps, privateModel?: boolean, parentId?: Id64String): Promise<Id64String[]>;
/** Create and insert a Drawing Partition element (in the repositoryModel). */
static createAndInsertDrawingPartition(testDb: IModelDb, newModelCode: CodeProps, parentId?: Id64String): Id64String;
/** Create and insert a DrawingModel associated with Drawing Partition. */
static createAndInsertDrawingModel(testDb: IModelDb, modeledElementRef: RelatedElement, privateModel?: boolean): Id64String;
/**
* Create and insert a Drawing Partition element (in the repositoryModel) and an associated DrawingModel.
* @return [modeledElementId, modelId]
*/
static createAndInsertDrawingPartitionAndModel(testImodel: IModelDb, newModelCode: CodeProps, privateModel?: boolean, parent?: Id64String): Id64String[];
static getUniqueSpatialCategoryCode(scopeModel: Model, newCodeBaseValue: string): Code;
static createPhysicalObject(testImodel: IModelDb, modelId: Id64String, categoryId: Id64String, elemCode?: Code): Element;
static registerTestBimSchema(): void;
static executeQuery(db: IModelDb, ecsql: string, bindings?: any[] | object): any[];
static createJobSubjectElement(iModel: IModelDb, name: string): Subject;
/** Flushes the Txns in the TxnTable - this allows importing of schemas */
static flushTxns(iModelDb: IModelDb): boolean;
static querySubjectId(iModelDb: IModelDb, subjectCodeValue: string): Id64String;
static queryDefinitionPartitionId(iModelDb: IModelDb, parentSubjectId: Id64String, suffix: string): Id64String;
static querySpatialCategoryId(iModelDb: IModelDb, modelId: Id64String, suffix: string): Id64String;
static queryPhysicalPartitionId(iModelDb: IModelDb, parentSubjectId: Id64String, suffix: string): Id64String;
static queryPhysicalElementId(iModelDb: IModelDb, modelId: Id64String, categoryId: Id64String, suffix: string): Id64String;
static insertSpatialCategory(iModelDb: IModelDb, modelId: Id64String, categoryName: string, color: ColorDef): Id64String;
static createBoxes(subCategoryIds: Id64String[]): GeometryStreamProps;
static createBox(size: Point3d, categoryId?: Id64String, subCategoryId?: Id64String, renderMaterialId?: Id64String, geometryPartId?: Id64String): GeometryStreamProps;
static createCylinder(radius: number): GeometryStreamProps;
static createRectangle(size: Point2d): GeometryStreamProps;
static insertTextureElement(iModelDb: IModelDb, modelId: Id64String, textureName: string): Id64String;
static queryByUserLabel(iModelDb: IModelDb, userLabel: string): Id64String;
static queryByCodeValue(iModelDb: IModelDb, codeValue: string): Id64String;
static insertRepositoryLink(iModelDb: IModelDb, codeValue: string, url: string, format: string): Id64String;
static insertExternalSource(iModelDb: IModelDb, repositoryId: Id64String, userLabel: string): Id64String;
static dumpIModelInfo(iModelDb: IModelDb): void;
}
export declare class ExtensiveTestScenario {
static uniqueAspectGuid: string;
static federationGuid3: string;
static prepareDb(sourceDb: IModelDb): Promise<void>;
static populateDb(sourceDb: IModelDb): Promise<void>;
static updateDb(sourceDb: IModelDb): void;
static assertUpdatesInDb(iModelDb: IModelDb, assertDeletes?: boolean): void;
}
//# sourceMappingURL=IModelTestUtils.d.ts.map