@itwin/core-backend 5.2.0-dev.5 → 5.2.0-dev.7
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.
- package/lib/cjs/BriefcaseManager.js +2 -2
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.js +2 -2
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/IModelDb.js +1 -1
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/internal/annotations/fields.d.ts.map +1 -1
- package/lib/cjs/internal/annotations/fields.js +1 -0
- package/lib/cjs/internal/annotations/fields.js.map +1 -1
- package/lib/cjs/internal/workspace/SettingsImpl.js +1 -1
- package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -1
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +2 -2
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -1
- package/lib/esm/BriefcaseManager.js +2 -2
- package/lib/esm/BriefcaseManager.js.map +1 -1
- package/lib/esm/ClassRegistry.js +2 -2
- package/lib/esm/ClassRegistry.js.map +1 -1
- package/lib/esm/IModelDb.js +1 -1
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/internal/annotations/fields.d.ts.map +1 -1
- package/lib/esm/internal/annotations/fields.js +2 -1
- package/lib/esm/internal/annotations/fields.js.map +1 -1
- package/lib/esm/internal/workspace/SettingsImpl.js +1 -1
- package/lib/esm/internal/workspace/SettingsImpl.js.map +1 -1
- package/lib/esm/internal/workspace/SettingsSchemasImpl.js +2 -2
- package/lib/esm/internal/workspace/SettingsSchemasImpl.js.map +1 -1
- package/lib/esm/test/ecsql/dataset/ECSqlDatasets.d.ts.map +1 -1
- package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js +8 -2
- package/lib/esm/test/ecsql/dataset/ECSqlDatasets.js.map +1 -1
- package/lib/esm/test/standalone/NativeAppStorage.test.js +2 -2
- package/lib/esm/test/standalone/NativeAppStorage.test.js.map +1 -1
- package/package.json +13 -13
|
@@ -241,7 +241,7 @@ class BriefcaseManager {
|
|
|
241
241
|
IModelJsFs_1.IModelJsFs.unlinkSync(filePath);
|
|
242
242
|
}
|
|
243
243
|
catch (err) {
|
|
244
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);
|
|
244
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, `cannot delete briefcase file ${String(err)}`);
|
|
245
245
|
}
|
|
246
246
|
// next, delete all files that start with the briefcase's filePath (e.g. "a.bim-locks", "a.bim-journal", etc.)
|
|
247
247
|
try {
|
|
@@ -264,7 +264,7 @@ class BriefcaseManager {
|
|
|
264
264
|
IModelJsFs_1.IModelJsFs.unlinkSync(pathname);
|
|
265
265
|
}
|
|
266
266
|
catch (error) {
|
|
267
|
-
core_bentley_1.Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);
|
|
267
|
+
core_bentley_1.Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${String(error)}`);
|
|
268
268
|
return false;
|
|
269
269
|
}
|
|
270
270
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BriefcaseManager.js","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAqC;AAErC,6BAA6B;AAC7B,sDAE6B;AAC7B,oDAG4B;AAE5B,mEAAgE;AAChE,2DAA2F;AAC3F,yCAA6D;AAC7D,6CAA0C;AAC1C,6CAA0C;AAC1C,6CAA0C;AAC1C,gDAA6E;AAC7E,8DAAyD;AAEzD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AA0EtD;;GAEG;AACH,MAAa,gBAAgB;IAC3B,wFAAwF;IACjF,MAAM,CAAC,aAAa,CAAC,QAAoB,IAAkB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAA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H,CAAC;oBAAS,CAAC;gBACT,uBAAU,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,GAAoB;QACrE,IAAI,UAAU,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,MAAM,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACvD,IAAI,CAAC,EAAE,CAAC,4BAA4B;oBAClC,MAAM,uBAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5B,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,IAAI,UAAU,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,8BAAe,CAAC,cAAc;oBACzE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;;AAljBH,4CAojBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\n// cspell:ignore cset csets ecchanges\n\nimport * as path from \"path\";\nimport {\n AccessToken, BeDuration, ChangeSetStatus, DbResult, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode, Optional, StopWatch\n} from \"@itwin/core-bentley\";\nimport {\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\n} from \"@itwin/core-common\";\nimport { AcquireNewBriefcaseIdArg, DownloadChangesetArg, DownloadChangesetRangeArg, IModelNameArg } from \"./BackendHubAccess\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\nimport { IModelHost } from \"./IModelHost\";\nimport { IModelJsFs } from \"./IModelJsFs\";\nimport { SchemaSync } from \"./SchemaSync\";\nimport { _hubAccess, _nativeDb, _releaseAllLocks } from \"./internal/Symbols\";\nimport { IModelNative } from \"./internal/NativePlatform\";\n\nconst loggerCategory = BackendLoggerCategory.IModelDb;\n\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\n * @public\n*/\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n}\n\n/**\n * Parameters for pushing changesets to iModelHub\n * @public\n */\nexport interface PushChangesArgs extends TokenArg {\n /** A description of the changes. This is visible on the iModel's timeline. */\n description: string;\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\n retainLocks?: true;\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\n mergeRetryCount?: number;\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\n mergeRetryDelay?: BeDuration;\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\n pushRetryCount?: number;\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\n pushRetryDelay?: BeDuration;\n /**\n * For testing purpose\n * @internal\n */\n noFastForward?: true;\n}\n\n/**\n * Specifies a specific index for pulling changes.\n * @public\n */\nexport interface ToChangesetArgs extends TokenArg {\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\n toIndex?: ChangesetIndex;\n}\n\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\n * @public\n */\nexport type PullChangesArgs = ToChangesetArgs & {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n /**\n * For testing purpose\n * @internal\n */\n noFastForward?: true;\n};\n\n/** Arguments for [[BriefcaseManager.revertTimelineChanges]]\n * @public\n */\nexport type RevertChangesArgs = Optional<PushChangesArgs, \"description\"> & {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n /** The index of the changeset to revert to */\n toIndex: ChangesetIndex;\n /** If present, schema changes are skipped during the revert operation. */\n skipSchemaChanges?: true;\n};\n\n/** Manages downloading Briefcases and downloading and uploading changesets.\n * @public\n */\nexport class BriefcaseManager {\n /** Get the local path of the folder storing files that are associated with an imodel */\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\n\n /** @internal */\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\n\n /** @internal */\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\n\n /** @internal */\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\n\n private static _briefcaseSubDir = \"briefcases\";\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\n }\n\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\n * @param briefcase the iModelId and BriefcaseId for the filename\n * @see getIModelPath\n */\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\n }\n\n private static setupCacheDir(cacheRootDir: LocalDirName) {\n this._cacheDir = cacheRootDir;\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\n }\n\n private static _initialized?: boolean;\n /** Initialize BriefcaseManager\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\n */\n public static initialize(cacheRootDir: LocalDirName) {\n if (this._initialized)\n return;\n this.setupCacheDir(cacheRootDir);\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\n this._initialized = true;\n }\n\n private static finalize() {\n this._initialized = false;\n }\n\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\n * iModels in the briefcase cache are returned.\n * @note usually there should only be one briefcase per iModel.\n */\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\n const briefcaseList: LocalBriefcaseProps[] = [];\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\n for (const iModelDir of iModelDirs) {\n if (iModelId && iModelId !== iModelDir)\n continue;\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\n try {\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\n continue;\n } catch {\n continue;\n }\n\n const briefcases = IModelJsFs.readdirSync(bcPath);\n for (const briefcaseName of briefcases) {\n if (briefcaseName.endsWith(\".bim\")) {\n try {\n const fileName = path.join(bcPath, briefcaseName);\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\n db.closeFile();\n } catch { }\n }\n }\n }\n return briefcaseList;\n }\n\n private static _cacheDir: LocalDirName;\n /** Get the root directory for the briefcase cache */\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\n\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\n * @note this does check whether the id was actually acquired by the caller.\n */\n public static isValidBriefcaseId(id: BriefcaseId) {\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\n }\n\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\n * it's a good idea to supply different aliases for each of them.\n */\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\n return IModelHost[_hubAccess].acquireNewBriefcaseId(arg);\n }\n\n /**\n * Download a new briefcase from iModelHub for the supplied iModelId.\n *\n * Briefcases are local files holding a copy of an iModel.\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\n *\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\n *\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\n *\n * @param arg The arguments that specify the briefcase file to be downloaded.\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\n * for the IModelId.\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\n */\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\n\n if (IModelJsFs.existsSync(fileName))\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\n\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\n const changeset = await IModelHost[_hubAccess].getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\n const checkpoint: CheckpointProps = { ...arg, changeset };\n\n try {\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\n } catch (error: unknown) {\n const errorMessage = `Failed to download briefcase to ${fileName}, errorMessage: ${(error as Error).message}`;\n if (arg.accessToken && arg.briefcaseId === undefined) {\n Logger.logInfo(loggerCategory, `${errorMessage}, releasing the briefcaseId...`);\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\n }\n if (IModelJsFs.existsSync(fileName)) {\n if (arg.accessToken && arg.briefcaseId === undefined)\n Logger.logTrace(loggerCategory, `Deleting the file: ${fileName}...`);\n else\n Logger.logInfo(loggerCategory, `${errorMessage}, deleting the file...`);\n try {\n IModelJsFs.unlinkSync(fileName);\n Logger.logInfo(loggerCategory, `Deleted ${fileName}`);\n } catch (deleteError: unknown) {\n Logger.logWarning(loggerCategory, `Failed to delete ${fileName}. errorMessage: ${(deleteError as Error).message}`);\n }\n }\n throw error;\n }\n\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\n const response: LocalBriefcaseProps = {\n fileName,\n briefcaseId,\n iModelId: arg.iModelId,\n iTwinId: arg.iTwinId,\n changeset: checkpoint.changeset,\n fileSize,\n };\n\n // now open the downloaded checkpoint and reset its BriefcaseId\n const nativeDb = new IModelNative.platform.DgnDb();\n try {\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\n } catch (err: any) {\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\n }\n try {\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\n nativeDb.resetBriefcaseId(briefcaseId);\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\n } finally {\n nativeDb.saveChanges();\n nativeDb.closeFile();\n }\n return response;\n }\n\n /** Deletes change sets of an iModel from local disk\n * @internal\n */\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\n }\n\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\n * @see deleteBriefcaseFiles\n */\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\n return IModelHost[_hubAccess].releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\n }\n\n /**\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\n * associated files (that is, all files in the same directory that start with the briefcase name).\n * @param filePath the full file name of the Briefcase to delete\n * @param accessToken for releasing the briefcaseId\n */\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\n try {\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\n const briefcase: BriefcaseProps = {\n iModelId: db.getIModelId(),\n briefcaseId: db.getBriefcaseId(),\n };\n db.closeFile();\n\n if (accessToken) {\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\n }\n }\n } catch { }\n\n // first try to delete the briefcase file\n try {\n if (IModelJsFs.existsSync(filePath))\n IModelJsFs.unlinkSync(filePath);\n } catch (err) {\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);\n }\n\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\n try {\n const dirName = path.dirname(filePath);\n const fileName = path.basename(filePath);\n const files = IModelJsFs.readdirSync(dirName);\n for (const file of files) {\n if (file.startsWith(fileName))\n this.deleteFile(path.join(dirName, file)); // don't throw on error\n }\n } catch { }\n }\n\n /** Deletes a file\n * - Does not throw any error, but logs it instead\n * - Returns true if the delete was successful\n */\n private static deleteFile(pathname: LocalFileName): boolean {\n try {\n IModelJsFs.unlinkSync(pathname);\n } catch (error) {\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);\n return false;\n }\n return true;\n }\n\n /** Deletes a folder, checking if it's empty\n * - Does not throw any error, but logs it instead\n * - Returns true if the delete was successful\n */\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\n try {\n const files = IModelJsFs.readdirSync(folderPathname);\n if (files.length > 0)\n return false;\n\n IModelJsFs.rmdirSync(folderPathname);\n } catch {\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\n return false;\n }\n return true;\n }\n\n /** Deletes the contents of a folder, but not the folder itself\n * - Does not throw any errors, but logs them.\n * - returns true if the delete was successful.\n */\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\n if (!IModelJsFs.existsSync(folderPathname))\n return false;\n\n let status = true;\n const files = IModelJsFs.readdirSync(folderPathname);\n for (const file of files) {\n const curPath = path.join(folderPathname, file);\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\n if (!locStatus)\n status = false;\n }\n return status;\n }\n\n /** Download all the changesets in the specified range.\n * @beta\n */\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\n return IModelHost[_hubAccess].downloadChangesets(arg);\n }\n\n /** Download a single changeset.\n * @beta\n */\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\n return IModelHost[_hubAccess].downloadChangeset(arg);\n }\n\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\n return IModelHost[_hubAccess].queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the hub for an array of changeset properties given a ChangesetRange */\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\n return IModelHost[_hubAccess].queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the hub for the ChangesetProps of the most recent changeset */\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\n return IModelHost[_hubAccess].getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the Id of an iModel by name.\n * @param arg Identifies the iModel of interest\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\n */\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\n return IModelHost[_hubAccess].queryIModelByName(arg);\n }\n\n /** Deletes a folder and all it's contents.\n * - Does not throw any errors, but logs them.\n * - returns true if the delete was successful.\n */\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\n if (!IModelJsFs.existsSync(folderPathname))\n return true;\n\n let status = false;\n status = BriefcaseManager.deleteFolderContents(folderPathname);\n if (!status)\n return false;\n\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\n return status;\n }\n\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps, fastForward: boolean) {\n if (changesetFile.changesType === ChangesetType.Schema || changesetFile.changesType === ChangesetType.SchemaSync)\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\n\n db[_nativeDb].applyChangeset(changesetFile, fastForward);\n db.changeset = db[_nativeDb].getCurrentChangeset();\n\n // we're done with this changeset, delete it\n IModelJsFs.removeSync(changesetFile.pathname);\n }\n\n /** @internal */\n public static async revertTimelineChanges(db: IModelDb, arg: RevertChangesArgs): Promise<void> {\n if (!db.isOpen || db[_nativeDb].isReadonly())\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to revert timeline changes\");\n\n let currentIndex = db.changeset.index;\n if (currentIndex === undefined)\n currentIndex = (await IModelHost[_hubAccess].queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\n\n if (!arg.toIndex) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"toIndex must be specified to revert changesets\");\n }\n if (arg.toIndex > currentIndex) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"toIndex must be less than or equal to the current index\");\n }\n if (!db.holdsSchemaLock) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"Cannot revert timeline changesets without holding a schema lock\");\n }\n\n // Download change sets\n const changesets = await IModelHost[_hubAccess].downloadChangesets({\n accessToken: arg.accessToken,\n iModelId: db.iModelId,\n range: { first: arg.toIndex, end: currentIndex },\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\n progressCallback: arg.onProgress,\n });\n\n if (changesets.length === 0)\n return;\n\n changesets.reverse();\n db.clearCaches();\n\n const stopwatch = new StopWatch(`Reverting changes`, true);\n Logger.logInfo(loggerCategory, `Starting reverting timeline changes from ${arg.toIndex} to ${currentIndex}`);\n\n /**\n * Revert timeline changes from the current index to the specified index.\n * It does not change parent of the current changeset.\n * All changes during revert operation are stored in a new changeset.\n * Revert operation require schema lock as we do not acquire individual locks for each element.\n * Optionally schema changes can be skipped (required for schema sync case).\n */\n db[_nativeDb].revertTimelineChanges(changesets, arg.skipSchemaChanges ?? false);\n Logger.logInfo(loggerCategory, `Reverted timeline changes from ${arg.toIndex} to ${currentIndex} (${stopwatch.elapsedSeconds} seconds)`);\n\n changesets.forEach((changeset) => {\n IModelJsFs.removeSync(changeset.pathname);\n });\n db.notifyChangesetApplied();\n }\n\n /** @internal */\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\n if (!db.isOpen || db[_nativeDb].isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\n\n let currentIndex = db.changeset.index;\n if (currentIndex === undefined)\n currentIndex = (await IModelHost[_hubAccess].queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\n\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\n\n if (db[_nativeDb].hasPendingTxns() && reverse) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"Cannot reverse changesets when there are pending changes\");\n }\n\n // Download change sets\n const changesets = await IModelHost[_hubAccess].downloadChangesets({\n accessToken: arg.accessToken,\n iModelId: db.iModelId,\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\n progressCallback: arg.onProgress,\n });\n\n if (changesets.length === 0)\n return; // nothing to apply\n\n if (reverse)\n changesets.reverse();\n\n\n let appliedChangesets = -1;\n if (db[_nativeDb].hasPendingTxns() && !reverse && !arg.noFastForward) {\n // attempt to perform fast forward\n for (const changeset of changesets) {\n // do not waste time on schema changesets. They cannot be fastforwarded.\n if (changeset.changesType === ChangesetType.Schema || changeset.changesType === ChangesetType.SchemaSync)\n break;\n\n try {\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description} using fast forward method`);\n await this.applySingleChangeset(db, changeset, true);\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\n appliedChangesets++;\n db.saveChanges();\n } catch {\n db.abandonChanges();\n break;\n }\n }\n }\n\n if (appliedChangesets < changesets.length - 1) {\n db[_nativeDb].pullMergeBegin();\n for (const changeset of changesets.filter((_, index) => index > appliedChangesets)) {\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);\n try {\n await this.applySingleChangeset(db, changeset, false);\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\n } catch (err: any) {\n if (err instanceof Error) {\n Logger.logError(loggerCategory, `Error applying changeset with id ${stopwatch.description}: ${err.message}`);\n }\n db.abandonChanges();\n db[_nativeDb].pullMergeEnd();\n throw err;\n }\n }\n db[_nativeDb].pullMergeEnd();\n if (!db.isReadonly) {\n db.saveChanges(\"Merge.\");\n }\n }\n\n // notify listeners\n db.notifyChangesetApplied();\n }\n /** create a changeset from the current changes, and push it to iModelHub */\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\n const changesetProps = db[_nativeDb].startCreateChangeset() as ChangesetFileProps;\n changesetProps.briefcaseId = db.briefcaseId;\n changesetProps.description = arg.description;\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\n if (!fileSize) // either undefined or 0 means error\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\n\n changesetProps.size = fileSize;\n const id = IModelNative.platform.DgnDb.computeChangesetId(changesetProps);\n if (id !== changesetProps.id) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR_InvalidChangeSetVersion, `Changeset id ${changesetProps.id} does not match computed id ${id}.`);\n }\n\n let retryCount = arg.pushRetryCount ?? 3;\n while (true) {\n try {\n const accessToken = await IModelHost.getAccessToken();\n const index = await IModelHost[_hubAccess].pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\n db[_nativeDb].completeCreateChangeset({ index });\n db.changeset = db[_nativeDb].getCurrentChangeset();\n if (!arg.retainLocks)\n await db.locks[_releaseAllLocks]();\n\n return;\n } catch (err: any) {\n const shouldRetry = () => {\n if (retryCount-- <= 0)\n return false;\n switch (err.errorNumber) {\n case IModelHubStatus.AnotherUserPushing:\n case IModelHubStatus.DatabaseTemporarilyLocked:\n case IModelHubStatus.OperationFailed:\n return true;\n }\n return false;\n };\n\n if (!shouldRetry()) {\n db[_nativeDb].abandonCreateChangeset();\n throw err;\n }\n } finally {\n IModelJsFs.removeSync(changesetProps.pathname);\n }\n }\n }\n\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\n * @internal\n */\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\n let retryCount = arg.mergeRetryCount ?? 5;\n while (true) {\n try {\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\n if (!db.skipSyncSchemasOnPullAndPush)\n await SchemaSync.pull(db);\n return await BriefcaseManager.pushChanges(db, arg);\n } catch (err: any) {\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\n throw (err);\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\n }\n }\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BriefcaseManager.js","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAqC;AAErC,6BAA6B;AAC7B,sDAE6B;AAC7B,oDAG4B;AAE5B,mEAAgE;AAChE,2DAA2F;AAC3F,yCAA6D;AAC7D,6CAA0C;AAC1C,6CAA0C;AAC1C,6CAA0C;AAC1C,gDAA6E;AAC7E,8DAAyD;AAEzD,MAAM,cAAc,GAAG,6CAAqB,CA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,CAAC;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC,CAAC;gBAEF,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;oBACnB,EAAE,CAAC,mBAAS,CAAC,CAAC,sBAAsB,EAAE,CAAC;oBACvC,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,uBAAU,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,GAAoB;QACrE,IAAI,UAAU,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,MAAM,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACvD,IAAI,CAAC,EAAE,CAAC,4BAA4B;oBAClC,MAAM,uBAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5B,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,IAAI,UAAU,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,8BAAe,CAAC,cAAc;oBACzE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;;AAljBH,4CAojBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module iModels\n */\n\n// cspell:ignore cset csets ecchanges\n\nimport * as path from \"path\";\nimport {\n AccessToken, BeDuration, ChangeSetStatus, DbResult, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode, Optional, StopWatch\n} from \"@itwin/core-bentley\";\nimport {\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\n} from \"@itwin/core-common\";\nimport { AcquireNewBriefcaseIdArg, DownloadChangesetArg, DownloadChangesetRangeArg, IModelNameArg } from \"./BackendHubAccess\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\nimport { IModelHost } from \"./IModelHost\";\nimport { IModelJsFs } from \"./IModelJsFs\";\nimport { SchemaSync } from \"./SchemaSync\";\nimport { _hubAccess, _nativeDb, _releaseAllLocks } from \"./internal/Symbols\";\nimport { IModelNative } from \"./internal/NativePlatform\";\n\nconst loggerCategory = BackendLoggerCategory.IModelDb;\n\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\n * @public\n*/\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n}\n\n/**\n * Parameters for pushing changesets to iModelHub\n * @public\n */\nexport interface PushChangesArgs extends TokenArg {\n /** A description of the changes. This is visible on the iModel's timeline. */\n description: string;\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\n retainLocks?: true;\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\n mergeRetryCount?: number;\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\n mergeRetryDelay?: BeDuration;\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\n pushRetryCount?: number;\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\n pushRetryDelay?: BeDuration;\n /**\n * For testing purpose\n * @internal\n */\n noFastForward?: true;\n}\n\n/**\n * Specifies a specific index for pulling changes.\n * @public\n */\nexport interface ToChangesetArgs extends TokenArg {\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\n toIndex?: ChangesetIndex;\n}\n\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\n * @public\n */\nexport type PullChangesArgs = ToChangesetArgs & {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n /**\n * For testing purpose\n * @internal\n */\n noFastForward?: true;\n};\n\n/** Arguments for [[BriefcaseManager.revertTimelineChanges]]\n * @public\n */\nexport type RevertChangesArgs = Optional<PushChangesArgs, \"description\"> & {\n /** If present, a function called periodically during the download to indicate progress.\n * @note return non-zero from this function to abort the download.\n */\n onProgress?: ProgressFunction;\n /** The index of the changeset to revert to */\n toIndex: ChangesetIndex;\n /** If present, schema changes are skipped during the revert operation. */\n skipSchemaChanges?: true;\n};\n\n/** Manages downloading Briefcases and downloading and uploading changesets.\n * @public\n */\nexport class BriefcaseManager {\n /** Get the local path of the folder storing files that are associated with an imodel */\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\n\n /** @internal */\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\n\n /** @internal */\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\n\n /** @internal */\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\n\n private static _briefcaseSubDir = \"briefcases\";\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\n }\n\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\n * @param briefcase the iModelId and BriefcaseId for the filename\n * @see getIModelPath\n */\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\n }\n\n private static setupCacheDir(cacheRootDir: LocalDirName) {\n this._cacheDir = cacheRootDir;\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\n }\n\n private static _initialized?: boolean;\n /** Initialize BriefcaseManager\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\n */\n public static initialize(cacheRootDir: LocalDirName) {\n if (this._initialized)\n return;\n this.setupCacheDir(cacheRootDir);\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\n this._initialized = true;\n }\n\n private static finalize() {\n this._initialized = false;\n }\n\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\n * iModels in the briefcase cache are returned.\n * @note usually there should only be one briefcase per iModel.\n */\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\n const briefcaseList: LocalBriefcaseProps[] = [];\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\n for (const iModelDir of iModelDirs) {\n if (iModelId && iModelId !== iModelDir)\n continue;\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\n try {\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\n continue;\n } catch {\n continue;\n }\n\n const briefcases = IModelJsFs.readdirSync(bcPath);\n for (const briefcaseName of briefcases) {\n if (briefcaseName.endsWith(\".bim\")) {\n try {\n const fileName = path.join(bcPath, briefcaseName);\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\n db.closeFile();\n } catch { }\n }\n }\n }\n return briefcaseList;\n }\n\n private static _cacheDir: LocalDirName;\n /** Get the root directory for the briefcase cache */\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\n\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\n * @note this does check whether the id was actually acquired by the caller.\n */\n public static isValidBriefcaseId(id: BriefcaseId) {\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\n }\n\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\n * it's a good idea to supply different aliases for each of them.\n */\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\n return IModelHost[_hubAccess].acquireNewBriefcaseId(arg);\n }\n\n /**\n * Download a new briefcase from iModelHub for the supplied iModelId.\n *\n * Briefcases are local files holding a copy of an iModel.\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\n *\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\n *\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\n *\n * @param arg The arguments that specify the briefcase file to be downloaded.\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\n * for the IModelId.\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\n */\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\n\n if (IModelJsFs.existsSync(fileName))\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\n\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\n const changeset = await IModelHost[_hubAccess].getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\n const checkpoint: CheckpointProps = { ...arg, changeset };\n\n try {\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\n } catch (error: unknown) {\n const errorMessage = `Failed to download briefcase to ${fileName}, errorMessage: ${(error as Error).message}`;\n if (arg.accessToken && arg.briefcaseId === undefined) {\n Logger.logInfo(loggerCategory, `${errorMessage}, releasing the briefcaseId...`);\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\n }\n if (IModelJsFs.existsSync(fileName)) {\n if (arg.accessToken && arg.briefcaseId === undefined)\n Logger.logTrace(loggerCategory, `Deleting the file: ${fileName}...`);\n else\n Logger.logInfo(loggerCategory, `${errorMessage}, deleting the file...`);\n try {\n IModelJsFs.unlinkSync(fileName);\n Logger.logInfo(loggerCategory, `Deleted ${fileName}`);\n } catch (deleteError: unknown) {\n Logger.logWarning(loggerCategory, `Failed to delete ${fileName}. errorMessage: ${(deleteError as Error).message}`);\n }\n }\n throw error;\n }\n\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\n const response: LocalBriefcaseProps = {\n fileName,\n briefcaseId,\n iModelId: arg.iModelId,\n iTwinId: arg.iTwinId,\n changeset: checkpoint.changeset,\n fileSize,\n };\n\n // now open the downloaded checkpoint and reset its BriefcaseId\n const nativeDb = new IModelNative.platform.DgnDb();\n try {\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\n } catch (err: any) {\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\n }\n try {\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\n nativeDb.resetBriefcaseId(briefcaseId);\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\n } finally {\n nativeDb.saveChanges();\n nativeDb.closeFile();\n }\n return response;\n }\n\n /** Deletes change sets of an iModel from local disk\n * @internal\n */\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\n }\n\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\n * @see deleteBriefcaseFiles\n */\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\n return IModelHost[_hubAccess].releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\n }\n\n /**\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\n * associated files (that is, all files in the same directory that start with the briefcase name).\n * @param filePath the full file name of the Briefcase to delete\n * @param accessToken for releasing the briefcaseId\n */\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\n try {\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\n const briefcase: BriefcaseProps = {\n iModelId: db.getIModelId(),\n briefcaseId: db.getBriefcaseId(),\n };\n db.closeFile();\n\n if (accessToken) {\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\n }\n }\n } catch { }\n\n // first try to delete the briefcase file\n try {\n if (IModelJsFs.existsSync(filePath))\n IModelJsFs.unlinkSync(filePath);\n } catch (err) {\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${String(err)}`);\n }\n\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\n try {\n const dirName = path.dirname(filePath);\n const fileName = path.basename(filePath);\n const files = IModelJsFs.readdirSync(dirName);\n for (const file of files) {\n if (file.startsWith(fileName))\n this.deleteFile(path.join(dirName, file)); // don't throw on error\n }\n } catch { }\n }\n\n /** Deletes a file\n * - Does not throw any error, but logs it instead\n * - Returns true if the delete was successful\n */\n private static deleteFile(pathname: LocalFileName): boolean {\n try {\n IModelJsFs.unlinkSync(pathname);\n } catch (error) {\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${String(error)}`);\n return false;\n }\n return true;\n }\n\n /** Deletes a folder, checking if it's empty\n * - Does not throw any error, but logs it instead\n * - Returns true if the delete was successful\n */\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\n try {\n const files = IModelJsFs.readdirSync(folderPathname);\n if (files.length > 0)\n return false;\n\n IModelJsFs.rmdirSync(folderPathname);\n } catch {\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\n return false;\n }\n return true;\n }\n\n /** Deletes the contents of a folder, but not the folder itself\n * - Does not throw any errors, but logs them.\n * - returns true if the delete was successful.\n */\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\n if (!IModelJsFs.existsSync(folderPathname))\n return false;\n\n let status = true;\n const files = IModelJsFs.readdirSync(folderPathname);\n for (const file of files) {\n const curPath = path.join(folderPathname, file);\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\n if (!locStatus)\n status = false;\n }\n return status;\n }\n\n /** Download all the changesets in the specified range.\n * @beta\n */\n public static async downloadChangesets(arg: DownloadChangesetRangeArg): Promise<ChangesetFileProps[]> {\n return IModelHost[_hubAccess].downloadChangesets(arg);\n }\n\n /** Download a single changeset.\n * @beta\n */\n public static async downloadChangeset(arg: DownloadChangesetArg): Promise<ChangesetFileProps> {\n return IModelHost[_hubAccess].downloadChangeset(arg);\n }\n\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\n return IModelHost[_hubAccess].queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the hub for an array of changeset properties given a ChangesetRange */\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\n return IModelHost[_hubAccess].queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the hub for the ChangesetProps of the most recent changeset */\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\n return IModelHost[_hubAccess].getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\n }\n\n /** Query the Id of an iModel by name.\n * @param arg Identifies the iModel of interest\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\n */\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\n return IModelHost[_hubAccess].queryIModelByName(arg);\n }\n\n /** Deletes a folder and all it's contents.\n * - Does not throw any errors, but logs them.\n * - returns true if the delete was successful.\n */\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\n if (!IModelJsFs.existsSync(folderPathname))\n return true;\n\n let status = false;\n status = BriefcaseManager.deleteFolderContents(folderPathname);\n if (!status)\n return false;\n\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\n return status;\n }\n\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps, fastForward: boolean) {\n if (changesetFile.changesType === ChangesetType.Schema || changesetFile.changesType === ChangesetType.SchemaSync)\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\n\n db[_nativeDb].applyChangeset(changesetFile, fastForward);\n db.changeset = db[_nativeDb].getCurrentChangeset();\n\n // we're done with this changeset, delete it\n IModelJsFs.removeSync(changesetFile.pathname);\n }\n\n /** @internal */\n public static async revertTimelineChanges(db: IModelDb, arg: RevertChangesArgs): Promise<void> {\n if (!db.isOpen || db[_nativeDb].isReadonly())\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to revert timeline changes\");\n\n let currentIndex = db.changeset.index;\n if (currentIndex === undefined)\n currentIndex = (await IModelHost[_hubAccess].queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\n\n if (!arg.toIndex) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"toIndex must be specified to revert changesets\");\n }\n if (arg.toIndex > currentIndex) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"toIndex must be less than or equal to the current index\");\n }\n if (!db.holdsSchemaLock) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"Cannot revert timeline changesets without holding a schema lock\");\n }\n\n // Download change sets\n const changesets = await IModelHost[_hubAccess].downloadChangesets({\n accessToken: arg.accessToken,\n iModelId: db.iModelId,\n range: { first: arg.toIndex, end: currentIndex },\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\n progressCallback: arg.onProgress,\n });\n\n if (changesets.length === 0)\n return;\n\n changesets.reverse();\n db.clearCaches();\n\n const stopwatch = new StopWatch(`Reverting changes`, true);\n Logger.logInfo(loggerCategory, `Starting reverting timeline changes from ${arg.toIndex} to ${currentIndex}`);\n\n /**\n * Revert timeline changes from the current index to the specified index.\n * It does not change parent of the current changeset.\n * All changes during revert operation are stored in a new changeset.\n * Revert operation require schema lock as we do not acquire individual locks for each element.\n * Optionally schema changes can be skipped (required for schema sync case).\n */\n db[_nativeDb].revertTimelineChanges(changesets, arg.skipSchemaChanges ?? false);\n Logger.logInfo(loggerCategory, `Reverted timeline changes from ${arg.toIndex} to ${currentIndex} (${stopwatch.elapsedSeconds} seconds)`);\n\n changesets.forEach((changeset) => {\n IModelJsFs.removeSync(changeset.pathname);\n });\n db.notifyChangesetApplied();\n }\n\n /** @internal */\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\n if (!db.isOpen || db[_nativeDb].isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\n\n let currentIndex = db.changeset.index;\n if (currentIndex === undefined)\n currentIndex = (await IModelHost[_hubAccess].queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\n\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\n\n if (db[_nativeDb].hasPendingTxns() && reverse) {\n throw new IModelError(ChangeSetStatus.ApplyError, \"Cannot reverse changesets when there are pending changes\");\n }\n\n // Download change sets\n const changesets = await IModelHost[_hubAccess].downloadChangesets({\n accessToken: arg.accessToken,\n iModelId: db.iModelId,\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\n progressCallback: arg.onProgress,\n });\n\n if (changesets.length === 0)\n return; // nothing to apply\n\n if (reverse)\n changesets.reverse();\n\n\n let appliedChangesets = -1;\n if (db[_nativeDb].hasPendingTxns() && !reverse && !arg.noFastForward) {\n // attempt to perform fast forward\n for (const changeset of changesets) {\n // do not waste time on schema changesets. They cannot be fastforwarded.\n if (changeset.changesType === ChangesetType.Schema || changeset.changesType === ChangesetType.SchemaSync)\n break;\n\n try {\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description} using fast forward method`);\n await this.applySingleChangeset(db, changeset, true);\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\n appliedChangesets++;\n db.saveChanges();\n } catch {\n db.abandonChanges();\n break;\n }\n }\n }\n\n if (appliedChangesets < changesets.length - 1) {\n db[_nativeDb].pullMergeBegin();\n for (const changeset of changesets.filter((_, index) => index > appliedChangesets)) {\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);\n try {\n await this.applySingleChangeset(db, changeset, false);\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\n } catch (err: any) {\n if (err instanceof Error) {\n Logger.logError(loggerCategory, `Error applying changeset with id ${stopwatch.description}: ${err.message}`);\n }\n db.abandonChanges();\n db[_nativeDb].pullMergeEnd();\n throw err;\n }\n }\n db[_nativeDb].pullMergeEnd();\n if (!db.isReadonly) {\n db.saveChanges(\"Merge.\");\n }\n }\n\n // notify listeners\n db.notifyChangesetApplied();\n }\n /** create a changeset from the current changes, and push it to iModelHub */\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\n const changesetProps = db[_nativeDb].startCreateChangeset() as ChangesetFileProps;\n changesetProps.briefcaseId = db.briefcaseId;\n changesetProps.description = arg.description;\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\n if (!fileSize) // either undefined or 0 means error\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\n\n changesetProps.size = fileSize;\n const id = IModelNative.platform.DgnDb.computeChangesetId(changesetProps);\n if (id !== changesetProps.id) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR_InvalidChangeSetVersion, `Changeset id ${changesetProps.id} does not match computed id ${id}.`);\n }\n\n let retryCount = arg.pushRetryCount ?? 3;\n while (true) {\n try {\n const accessToken = await IModelHost.getAccessToken();\n const index = await IModelHost[_hubAccess].pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\n db[_nativeDb].completeCreateChangeset({ index });\n db.changeset = db[_nativeDb].getCurrentChangeset();\n if (!arg.retainLocks)\n await db.locks[_releaseAllLocks]();\n\n return;\n } catch (err: any) {\n const shouldRetry = () => {\n if (retryCount-- <= 0)\n return false;\n switch (err.errorNumber) {\n case IModelHubStatus.AnotherUserPushing:\n case IModelHubStatus.DatabaseTemporarilyLocked:\n case IModelHubStatus.OperationFailed:\n return true;\n }\n return false;\n };\n\n if (!shouldRetry()) {\n db[_nativeDb].abandonCreateChangeset();\n throw err;\n }\n } finally {\n IModelJsFs.removeSync(changesetProps.pathname);\n }\n }\n }\n\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\n * @internal\n */\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\n let retryCount = arg.mergeRetryCount ?? 5;\n while (true) {\n try {\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\n if (!db.skipSyncSchemasOnPullAndPush)\n await SchemaSync.pull(db);\n return await BriefcaseManager.pushChanges(db, arg);\n } catch (err: any) {\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\n throw (err);\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\n }\n }\n }\n\n}\n"]}
|
package/lib/cjs/ClassRegistry.js
CHANGED
|
@@ -144,7 +144,7 @@ class ClassRegistry {
|
|
|
144
144
|
const domainName = name[0];
|
|
145
145
|
const className = name[1];
|
|
146
146
|
if (0 === entityMetaData.baseClasses.length) // metadata must contain a superclass
|
|
147
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadArg, `class ${
|
|
147
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadArg, `class ${entityMetaData.ecclass} has no superclass`);
|
|
148
148
|
// make sure schema exists
|
|
149
149
|
let schema = iModel.schemaMap.get(domainName) ?? Schema_1.Schemas.getRegisteredSchema(domainName);
|
|
150
150
|
if (undefined === schema)
|
|
@@ -152,7 +152,7 @@ class ClassRegistry {
|
|
|
152
152
|
const superClassFullName = entityMetaData.baseClasses[0].toLowerCase();
|
|
153
153
|
const superclass = iModel.jsClassMap.get(superClassFullName) ?? this._globalClassMap.get(superClassFullName);
|
|
154
154
|
if (undefined === superclass)
|
|
155
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `cannot find superclass for class ${
|
|
155
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `cannot find superclass for class ${entityMetaData.ecclass}`);
|
|
156
156
|
// user defined class hierarchies may skip a class in the hierarchy, and therefore their JS base class cannot
|
|
157
157
|
// be used to tell if there are any generated classes in the hierarchy
|
|
158
158
|
let generatedClassHasNonGeneratedNonCoreAncestor = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassRegistry.js","sourceRoot":"","sources":["../../src/ClassRegistry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAuF;AACvF,oDAAqG;AACrG,qCAAkC;AAElC,qCAA2C;AAC3C,yDAAsD;AACtD,iCAAiC;AACjC,gDAA+C;AAE/C,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAa,gBAAgB;IACV,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE9D,gBAAgB;IACT,GAAG,CAAC,aAAqB;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,C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e,CAAC,EAAE,CAAC;YACrD,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM;gBAC5B,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;;AAhPH,sCAiPC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,gBAAgB;IAC3B,4DAA4D;IACpD,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,cAAc,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEvD,wCAAwC;IACxC,4DAA4D;IACrD,IAAI,CAAC,aAAqB;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,4DAA4D;IACrD,aAAa,CAAC,OAAmB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1D,CAAC;IAED,gCAAgC;IAChC,4DAA4D;IACrD,GAAG,CAAC,aAAqB,EAAE,QAAwB;QACxD,MAAM,IAAI,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;CACF;AAxBD,4CAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Schema\n */\n\nimport { DbResult, Id64, Id64String, IModelStatus, Logger } from \"@itwin/core-bentley\";\nimport { EntityMetaData, EntityReferenceSet, IModelError, RelatedElement } from \"@itwin/core-common\";\nimport { Entity } from \"./Entity\";\nimport { IModelDb } from \"./IModelDb\";\nimport { Schema, Schemas } from \"./Schema\";\nimport { EntityReferences } from \"./EntityReferences\";\nimport * as assert from \"assert\";\nimport { _nativeDb } from \"./internal/Symbols\";\n\nconst isGeneratedClassTag = Symbol(\"isGeneratedClassTag\");\n\n/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in \"schema:class\" format) and the JavaScript [[Entity]] class that implements it.\n * @public\n */\nexport class EntityJsClassMap {\n private readonly _classMap = new Map<string, typeof Entity>();\n\n /** @internal */\n public has(classFullName: string): boolean {\n return this._classMap.has(classFullName.toLowerCase());\n }\n\n /** @internal */\n public get(classFullName: string): typeof Entity | undefined {\n return this._classMap.get(classFullName.toLowerCase());\n }\n\n /** @internal */\n public set(classFullName: string, entityClass: typeof Entity): void {\n this._classMap.set(classFullName.toLowerCase(), entityClass);\n }\n\n /** @internal */\n public delete(classFullName: string): boolean {\n return this._classMap.delete(classFullName.toLowerCase());\n }\n\n /** @internal */\n public clear(): void {\n this._classMap.clear();\n }\n\n /** @internal */\n public [Symbol.iterator](): IterableIterator<[string, typeof Entity]> {\n return this._classMap[Symbol.iterator]();\n }\n\n /**\n * Registers a single `entityClass` defined in the specified `schema`.\n * This method registers the class globally. To register a class for a specific iModel, use [[IModelDb.jsClassMap]].\n *\n * @param entityClass - The JavaScript class that implements the BIS [ECClass](@itwin/core-common) to be registered.\n * @param schema - The schema that contains the `entityClass`.\n *\n * @throws Error if the class is already registered.\n *\n * @public\n */\n public register(entityClass: typeof Entity, schema: typeof Schema): void {\n const key = (`${schema.schemaName}:${entityClass.className}`).toLowerCase();\n if (this.has(key)) {\n const errMsg = `Class ${key} is already registered. Make sure static className member is correct on JavaScript class ${entityClass.name}`;\n Logger.logError(\"core-frontend.classRegistry\", errMsg);\n throw new Error(errMsg);\n }\n entityClass.schema = schema;\n this.set(key, entityClass);\n }\n}\n\n/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in \"schema:class\" format) and the JavaScript [[Entity]] class that implements it.\n * Applications or modules that supply their own Entity subclasses should use [[registerModule]] or [[register]] at startup\n * to establish their mappings.\n *\n * When creating custom Entity subclasses for registration, you should:\n * - Override the `className` property to match your ECClass name:\n * ```typescript\n * public static override get className() { return \"TestElement\"; }\n * ```\n * - Do NOT override `schemaName` or `schema` - these will be wired up automatically during registration\n *\n * @public\n */\nexport class ClassRegistry {\n private static readonly _globalClassMap = new EntityJsClassMap();\n /** @internal */\n public static isNotFoundError(err: any) { return (err instanceof IModelError) && (err.errorNumber === IModelStatus.NotFound); }\n /** @internal */\n public static makeMetaDataNotFoundError(className: string): IModelError { return new IModelError(IModelStatus.NotFound, `metadata not found for ${className}`); }\n /** Register a single `entityClass` defined in the specified `schema`.\n * @see [[registerModule]] to register multiple classes.\n * @public\n */\n public static register(entityClass: typeof Entity, schema: typeof Schema) {\n this._globalClassMap.register(entityClass, schema);\n }\n\n /** Generate a proxy Schema for a domain that has not been registered. */\n private static generateProxySchema(domain: string, iModel: IModelDb): typeof Schema {\n const hasBehavior = iModel.withPreparedSqliteStatement(`\n SELECT NULL FROM [ec_CustomAttribute] [c]\n JOIN [ec_schema] [s] ON [s].[Id] = [c].[ContainerId]\n JOIN [ec_class] [e] ON [e].[Id] = [c].[ClassId]\n JOIN [ec_schema] [b] ON [e].[SchemaId] = [b].[Id]\n WHERE [c].[ContainerType] = 1 AND [s].[Name] = ? AND [b].[Name] || '.' || [e].[name] = ?`, (stmt) => {\n stmt.bindString(1, domain);\n stmt.bindString(2, \"BisCore.SchemaHasBehavior\");\n return stmt.step() === DbResult.BE_SQLITE_ROW;\n });\n\n const schemaClass = class extends Schema {\n public static override get schemaName() { return domain; }\n public static override get missingRequiredBehavior() { return hasBehavior; }\n };\n\n iModel.schemaMap.registerSchema(schemaClass); // register the class before we return it.\n return schemaClass;\n }\n\n /** First, finds the root BisCore entity class for an entity, by traversing base classes and mixin targets (AppliesTo).\n * Then, gets its metadata and returns that.\n * @param iModel - iModel containing the metadata for this type\n * @param ecTypeQualifier - a full name of an ECEntityClass to find the root of\n * @returns the qualified full name of an ECEntityClass\n * @internal public for testing only\n */\n public static getRootEntity(iModel: IModelDb, ecTypeQualifier: string): string {\n const [classSchema, className] = ecTypeQualifier.split(\".\");\n const schemaItemJson = iModel[_nativeDb].getSchemaItem(classSchema, className);\n if (schemaItemJson.error)\n throw new IModelError(schemaItemJson.error.status, `failed to get schema item '${ecTypeQualifier}'`);\n\n assert(undefined !== schemaItemJson.result);\n const schemaItem = JSON.parse(schemaItemJson.result);\n if (!(\"appliesTo\" in schemaItem) && schemaItem.baseClass === undefined) {\n return ecTypeQualifier;\n }\n\n // typescript doesn't understand that the inverse of the above condition is\n // (\"appliesTo\" in rootclassMetaData || rootClassMetaData.baseClass !== undefined)\n const parentItemQualifier = schemaItem.appliesTo ?? schemaItem.baseClass as string;\n return this.getRootEntity(iModel, parentItemQualifier);\n }\n\n /** Generate a JavaScript class from Entity metadata.\n * @param entityMetaData The Entity metadata that defines the class\n */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n private static generateClassForEntity(entityMetaData: EntityMetaData, iModel: IModelDb): typeof Entity {\n const name = entityMetaData.ecclass.split(\":\");\n const domainName = name[0];\n const className = name[1];\n\n if (0 === entityMetaData.baseClasses.length) // metadata must contain a superclass\n throw new IModelError(IModelStatus.BadArg, `class ${name} has no superclass`);\n\n // make sure schema exists\n let schema = iModel.schemaMap.get(domainName) ?? Schemas.getRegisteredSchema(domainName);\n if (undefined === schema)\n schema = this.generateProxySchema(domainName, iModel); // no schema found, create it too\n\n const superClassFullName = entityMetaData.baseClasses[0].toLowerCase();\n const superclass = iModel.jsClassMap.get(superClassFullName) ?? this._globalClassMap.get(superClassFullName);\n if (undefined === superclass)\n throw new IModelError(IModelStatus.NotFound, `cannot find superclass for class ${name}`);\n\n // user defined class hierarchies may skip a class in the hierarchy, and therefore their JS base class cannot\n // be used to tell if there are any generated classes in the hierarchy\n let generatedClassHasNonGeneratedNonCoreAncestor = false;\n let currentSuperclass = superclass;\n const MAX_ITERS = 1000;\n for (let i = 0; i < MAX_ITERS; ++i) {\n if (currentSuperclass.schema.schemaName === \"BisCore\")\n break;\n\n if (!currentSuperclass.isGeneratedClass) {\n generatedClassHasNonGeneratedNonCoreAncestor = true;\n break;\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const superclassMetaData = iModel.classMetaDataRegistry.find(currentSuperclass.classFullName);\n if (superclassMetaData === undefined)\n throw new IModelError(IModelStatus.BadSchema, `could not find the metadata for class '${currentSuperclass.name}', class metadata should be loaded by now`);\n const maybeNextSuperclass = this.getClass(superclassMetaData.baseClasses[0], iModel);\n if (maybeNextSuperclass === undefined)\n throw new IModelError(IModelStatus.BadSchema, `could not find the base class of '${currentSuperclass.name}', all generated classes must have a base class`);\n currentSuperclass = maybeNextSuperclass;\n }\n\n const generatedClass = class extends superclass {\n public static override get className() { return className; }\n private static [isGeneratedClassTag] = true;\n public static override get isGeneratedClass() { return this.hasOwnProperty(isGeneratedClassTag); }\n };\n\n // the above creates an anonymous class. For help debugging, set the \"constructor.name\" property to be the same as the bisClassName.\n Object.defineProperty(generatedClass, \"name\", { get: () => className }); // this is the (only) way to change that readonly property.\n\n // a class only gets an automatic `collectReferenceIds` implementation if:\n // - it is not in the `BisCore` schema\n // - there are no ancestors with manually registered JS implementations, (excluding BisCore base classes)\n if (!generatedClassHasNonGeneratedNonCoreAncestor) {\n const navigationProps = Object.entries(entityMetaData.properties)\n .filter(([_name, prop]) => prop.isNavigation)\n // eslint-disable-next-line @typescript-eslint/no-shadow\n .map(([name, prop]) => {\n assert(prop.relationshipClass);\n const maybeMetaData = iModel[_nativeDb].getSchemaItem(...prop.relationshipClass.split(\":\") as [string, string]);\n assert(maybeMetaData.result !== undefined, \"The nav props relationship metadata was not found\");\n const relMetaData = JSON.parse(maybeMetaData.result);\n const rootClassMetaData = ClassRegistry.getRootEntity(iModel, relMetaData.target.constraintClasses[0]);\n // root class must be in BisCore so should be loaded since biscore classes will never get this\n // generated implementation\n const normalizeClassName = (clsName: string) => clsName.replace(\".\", \":\");\n const rootClass = ClassRegistry.findRegisteredClass(normalizeClassName(rootClassMetaData));\n assert(rootClass, `The root class for ${prop.relationshipClass} was not in BisCore.`);\n return { name, concreteEntityType: EntityReferences.typeFromClass(rootClass) };\n });\n\n Object.defineProperty(\n generatedClass.prototype,\n \"collectReferenceIds\",\n {\n value(this: typeof generatedClass, referenceIds: EntityReferenceSet) {\n // eslint-disable-next-line @typescript-eslint/dot-notation\n const superImpl = superclass.prototype[\"collectReferenceIds\"];\n superImpl.call(this, referenceIds);\n for (const navProp of navigationProps) {\n const relatedElem: RelatedElement | undefined = (this as any)[navProp.name]; // cast to any since subclass can have any extensions\n if (!relatedElem || !Id64.isValid(relatedElem.id))\n continue;\n const referenceId = EntityReferences.fromEntityType(relatedElem.id, navProp.concreteEntityType);\n referenceIds.add(referenceId);\n }\n },\n // defaults for methods on a prototype (required for sinon to stub out methods on tests)\n writable: true,\n configurable: true,\n },\n );\n }\n\n // if the schema is a proxy for a domain with behavior, throw exceptions for all protected operations\n if (schema.missingRequiredBehavior) {\n const throwError = () => {\n throw new IModelError(IModelStatus.WrongHandler, `Schema [${domainName}] not registered, but is marked with SchemaHasBehavior`);\n };\n\n superclass.protectedOperations.forEach((operation) => (generatedClass as any)[operation] = throwError);\n }\n\n iModel.jsClassMap.register(generatedClass, schema); // register it before returning\n return generatedClass;\n }\n\n /** Register all of the classes found in the given module that derive from [[Entity]].\n * [[register]] will be invoked for each subclass of `Entity` exported by `moduleObj`.\n * @param moduleObj The module to search for subclasses of Entity\n * @param schema The schema that contains all of the [ECClass]($ecschema-metadata)es exported by `moduleObj`.\n */\n public static registerModule(moduleObj: any, schema: typeof Schema) {\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\n const thisClass = moduleObj[thisMember];\n if (thisClass.prototype instanceof Entity)\n this.register(thisClass, schema);\n }\n }\n\n /**\n * This function fetches the specified Entity from the imodel, generates a JavaScript class for it, and registers the generated\n * class. This function also ensures that all of the base classes of the Entity exist and are registered.\n */\n private static generateClass(classFullName: string, iModel: IModelDb): typeof Entity {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const metadata: EntityMetaData | undefined = iModel.classMetaDataRegistry.find(classFullName);\n if (metadata === undefined || metadata.ecclass === undefined)\n throw this.makeMetaDataNotFoundError(classFullName);\n\n // Make sure we have all base classes registered.\n if (metadata.baseClasses && (0 !== metadata.baseClasses.length))\n this.getClass(metadata.baseClasses[0], iModel);\n\n // Now we can generate the class from the classDef.\n return this.generateClassForEntity(metadata, iModel);\n }\n\n /** Find a registered class by classFullName.\n * @param classFullName class to find\n * @param iModel The IModel that contains the class definitions\n * @returns The Entity class or undefined\n */\n public static findRegisteredClass(classFullName: string): typeof Entity | undefined {\n return this._globalClassMap.get(classFullName.toLowerCase());\n }\n\n /** Get the Entity class for the specified Entity className.\n * @param classFullName The full BIS class name of the Entity\n * @param iModel The IModel that contains the class definitions\n * @returns The Entity class\n */\n public static getClass(classFullName: string, iModel: IModelDb): typeof Entity {\n const key = classFullName.toLowerCase();\n return iModel.jsClassMap.get(key) ?? this._globalClassMap.get(key) ?? this.generateClass(key, iModel);\n }\n\n /** Unregister a class, by name, if one is already registered.\n * This function is not normally needed, but is useful for cases where a generated *proxy* class needs to be replaced by the *real* class.\n * @param classFullName Name of the class to unregister\n * @return true if the class was unregistered\n * @internal\n */\n public static unregisterClass(classFullName: string) { return this._globalClassMap.delete(classFullName.toLowerCase()); }\n\n /** Unregister all classes from a schema.\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\n * @param schema Name of the schema to unregister\n * @internal\n */\n public static unregisterClassesFrom(schema: typeof Schema) {\n for (const entry of Array.from(this._globalClassMap)) {\n if (entry[1].schema === schema)\n this.unregisterClass(entry[0]);\n }\n }\n}\n\n/**\n * A cache that records the mapping between class names and class metadata.\n * @see [[IModelDb.classMetaDataRegistry]] to access the registry for a specific iModel.\n * @internal\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Please use `schemaContext` from the `iModel` instead.\n *\n * @example\n * @\n * Current Usage:\n * ```ts\n * const metaData: EntityMetaData | undefined = iModel.classMetaDataRegistry.find(\"SchemaName:ClassName\");\n * ```\n *\n * Replacement:\n * ```ts\n * const entityMetaData: EntityClass | undefined = iModel.schemaContext.getSchemaItemSync(\"SchemaName.ClassName\", EntityClass);\n * const relationshipMetaData: RelationshipClass | undefined = iModel.schemaContext.getSchemaItemSync(\"SchemaName\", \"ClassName\", RelationshipClass);\n * ```\n */\nexport class MetaDataRegistry {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n private _registry = new Map<string, EntityMetaData>();\n private _classIdToName = new Map<Id64String, string>();\n\n /** Get the specified Entity metadata */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public find(classFullName: string): EntityMetaData | undefined {\n return this._registry.get(classFullName.toLowerCase());\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public findByClassId(classId: Id64String): EntityMetaData | undefined {\n const name = this._classIdToName.get(classId);\n return undefined !== name ? this.find(name) : undefined;\n }\n\n /** Add metadata to the cache */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public add(classFullName: string, metaData: EntityMetaData): void {\n const name = classFullName.toLowerCase();\n this._registry.set(name, metaData);\n this._classIdToName.set(metaData.classId, name);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClassRegistry.js","sourceRoot":"","sources":["../../src/ClassRegistry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAuF;AACvF,oDAAqG;AACrG,qCAAkC;AAElC,qCAA2C;AAC3C,yDAAsD;AACtD,iCAAiC;AACjC,gDAA+C;AAE/C,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAE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xBD,4CAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Schema\n */\n\nimport { DbResult, Id64, Id64String, IModelStatus, Logger } from \"@itwin/core-bentley\";\nimport { EntityMetaData, EntityReferenceSet, IModelError, RelatedElement } from \"@itwin/core-common\";\nimport { Entity } from \"./Entity\";\nimport { IModelDb } from \"./IModelDb\";\nimport { Schema, Schemas } from \"./Schema\";\nimport { EntityReferences } from \"./EntityReferences\";\nimport * as assert from \"assert\";\nimport { _nativeDb } from \"./internal/Symbols\";\n\nconst isGeneratedClassTag = Symbol(\"isGeneratedClassTag\");\n\n/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in \"schema:class\" format) and the JavaScript [[Entity]] class that implements it.\n * @public\n */\nexport class EntityJsClassMap {\n private readonly _classMap = new Map<string, typeof Entity>();\n\n /** @internal */\n public has(classFullName: string): boolean {\n return this._classMap.has(classFullName.toLowerCase());\n }\n\n /** @internal */\n public get(classFullName: string): typeof Entity | undefined {\n return this._classMap.get(classFullName.toLowerCase());\n }\n\n /** @internal */\n public set(classFullName: string, entityClass: typeof Entity): void {\n this._classMap.set(classFullName.toLowerCase(), entityClass);\n }\n\n /** @internal */\n public delete(classFullName: string): boolean {\n return this._classMap.delete(classFullName.toLowerCase());\n }\n\n /** @internal */\n public clear(): void {\n this._classMap.clear();\n }\n\n /** @internal */\n public [Symbol.iterator](): IterableIterator<[string, typeof Entity]> {\n return this._classMap[Symbol.iterator]();\n }\n\n /**\n * Registers a single `entityClass` defined in the specified `schema`.\n * This method registers the class globally. To register a class for a specific iModel, use [[IModelDb.jsClassMap]].\n *\n * @param entityClass - The JavaScript class that implements the BIS [ECClass](@itwin/core-common) to be registered.\n * @param schema - The schema that contains the `entityClass`.\n *\n * @throws Error if the class is already registered.\n *\n * @public\n */\n public register(entityClass: typeof Entity, schema: typeof Schema): void {\n const key = (`${schema.schemaName}:${entityClass.className}`).toLowerCase();\n if (this.has(key)) {\n const errMsg = `Class ${key} is already registered. Make sure static className member is correct on JavaScript class ${entityClass.name}`;\n Logger.logError(\"core-frontend.classRegistry\", errMsg);\n throw new Error(errMsg);\n }\n entityClass.schema = schema;\n this.set(key, entityClass);\n }\n}\n\n/** Maintains the mapping between the name of a BIS [ECClass]($ecschema-metadata) (in \"schema:class\" format) and the JavaScript [[Entity]] class that implements it.\n * Applications or modules that supply their own Entity subclasses should use [[registerModule]] or [[register]] at startup\n * to establish their mappings.\n *\n * When creating custom Entity subclasses for registration, you should:\n * - Override the `className` property to match your ECClass name:\n * ```typescript\n * public static override get className() { return \"TestElement\"; }\n * ```\n * - Do NOT override `schemaName` or `schema` - these will be wired up automatically during registration\n *\n * @public\n */\nexport class ClassRegistry {\n private static readonly _globalClassMap = new EntityJsClassMap();\n /** @internal */\n public static isNotFoundError(err: any) { return (err instanceof IModelError) && (err.errorNumber === IModelStatus.NotFound); }\n /** @internal */\n public static makeMetaDataNotFoundError(className: string): IModelError { return new IModelError(IModelStatus.NotFound, `metadata not found for ${className}`); }\n /** Register a single `entityClass` defined in the specified `schema`.\n * @see [[registerModule]] to register multiple classes.\n * @public\n */\n public static register(entityClass: typeof Entity, schema: typeof Schema) {\n this._globalClassMap.register(entityClass, schema);\n }\n\n /** Generate a proxy Schema for a domain that has not been registered. */\n private static generateProxySchema(domain: string, iModel: IModelDb): typeof Schema {\n const hasBehavior = iModel.withPreparedSqliteStatement(`\n SELECT NULL FROM [ec_CustomAttribute] [c]\n JOIN [ec_schema] [s] ON [s].[Id] = [c].[ContainerId]\n JOIN [ec_class] [e] ON [e].[Id] = [c].[ClassId]\n JOIN [ec_schema] [b] ON [e].[SchemaId] = [b].[Id]\n WHERE [c].[ContainerType] = 1 AND [s].[Name] = ? AND [b].[Name] || '.' || [e].[name] = ?`, (stmt) => {\n stmt.bindString(1, domain);\n stmt.bindString(2, \"BisCore.SchemaHasBehavior\");\n return stmt.step() === DbResult.BE_SQLITE_ROW;\n });\n\n const schemaClass = class extends Schema {\n public static override get schemaName() { return domain; }\n public static override get missingRequiredBehavior() { return hasBehavior; }\n };\n\n iModel.schemaMap.registerSchema(schemaClass); // register the class before we return it.\n return schemaClass;\n }\n\n /** First, finds the root BisCore entity class for an entity, by traversing base classes and mixin targets (AppliesTo).\n * Then, gets its metadata and returns that.\n * @param iModel - iModel containing the metadata for this type\n * @param ecTypeQualifier - a full name of an ECEntityClass to find the root of\n * @returns the qualified full name of an ECEntityClass\n * @internal public for testing only\n */\n public static getRootEntity(iModel: IModelDb, ecTypeQualifier: string): string {\n const [classSchema, className] = ecTypeQualifier.split(\".\");\n const schemaItemJson = iModel[_nativeDb].getSchemaItem(classSchema, className);\n if (schemaItemJson.error)\n throw new IModelError(schemaItemJson.error.status, `failed to get schema item '${ecTypeQualifier}'`);\n\n assert(undefined !== schemaItemJson.result);\n const schemaItem = JSON.parse(schemaItemJson.result);\n if (!(\"appliesTo\" in schemaItem) && schemaItem.baseClass === undefined) {\n return ecTypeQualifier;\n }\n\n // typescript doesn't understand that the inverse of the above condition is\n // (\"appliesTo\" in rootclassMetaData || rootClassMetaData.baseClass !== undefined)\n const parentItemQualifier = schemaItem.appliesTo ?? schemaItem.baseClass as string;\n return this.getRootEntity(iModel, parentItemQualifier);\n }\n\n /** Generate a JavaScript class from Entity metadata.\n * @param entityMetaData The Entity metadata that defines the class\n */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n private static generateClassForEntity(entityMetaData: EntityMetaData, iModel: IModelDb): typeof Entity {\n const name = entityMetaData.ecclass.split(\":\");\n const domainName = name[0];\n const className = name[1];\n\n if (0 === entityMetaData.baseClasses.length) // metadata must contain a superclass\n throw new IModelError(IModelStatus.BadArg, `class ${entityMetaData.ecclass} has no superclass`);\n\n // make sure schema exists\n let schema = iModel.schemaMap.get(domainName) ?? Schemas.getRegisteredSchema(domainName);\n if (undefined === schema)\n schema = this.generateProxySchema(domainName, iModel); // no schema found, create it too\n\n const superClassFullName = entityMetaData.baseClasses[0].toLowerCase();\n const superclass = iModel.jsClassMap.get(superClassFullName) ?? this._globalClassMap.get(superClassFullName);\n if (undefined === superclass)\n throw new IModelError(IModelStatus.NotFound, `cannot find superclass for class ${entityMetaData.ecclass}`);\n\n // user defined class hierarchies may skip a class in the hierarchy, and therefore their JS base class cannot\n // be used to tell if there are any generated classes in the hierarchy\n let generatedClassHasNonGeneratedNonCoreAncestor = false;\n let currentSuperclass = superclass;\n const MAX_ITERS = 1000;\n for (let i = 0; i < MAX_ITERS; ++i) {\n if (currentSuperclass.schema.schemaName === \"BisCore\")\n break;\n\n if (!currentSuperclass.isGeneratedClass) {\n generatedClassHasNonGeneratedNonCoreAncestor = true;\n break;\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const superclassMetaData = iModel.classMetaDataRegistry.find(currentSuperclass.classFullName);\n if (superclassMetaData === undefined)\n throw new IModelError(IModelStatus.BadSchema, `could not find the metadata for class '${currentSuperclass.name}', class metadata should be loaded by now`);\n const maybeNextSuperclass = this.getClass(superclassMetaData.baseClasses[0], iModel);\n if (maybeNextSuperclass === undefined)\n throw new IModelError(IModelStatus.BadSchema, `could not find the base class of '${currentSuperclass.name}', all generated classes must have a base class`);\n currentSuperclass = maybeNextSuperclass;\n }\n\n const generatedClass = class extends superclass {\n public static override get className() { return className; }\n private static [isGeneratedClassTag] = true;\n public static override get isGeneratedClass() { return this.hasOwnProperty(isGeneratedClassTag); }\n };\n\n // the above creates an anonymous class. For help debugging, set the \"constructor.name\" property to be the same as the bisClassName.\n Object.defineProperty(generatedClass, \"name\", { get: () => className }); // this is the (only) way to change that readonly property.\n\n // a class only gets an automatic `collectReferenceIds` implementation if:\n // - it is not in the `BisCore` schema\n // - there are no ancestors with manually registered JS implementations, (excluding BisCore base classes)\n if (!generatedClassHasNonGeneratedNonCoreAncestor) {\n const navigationProps = Object.entries(entityMetaData.properties)\n .filter(([_name, prop]) => prop.isNavigation)\n // eslint-disable-next-line @typescript-eslint/no-shadow\n .map(([name, prop]) => {\n assert(prop.relationshipClass);\n const maybeMetaData = iModel[_nativeDb].getSchemaItem(...prop.relationshipClass.split(\":\") as [string, string]);\n assert(maybeMetaData.result !== undefined, \"The nav props relationship metadata was not found\");\n const relMetaData = JSON.parse(maybeMetaData.result);\n const rootClassMetaData = ClassRegistry.getRootEntity(iModel, relMetaData.target.constraintClasses[0]);\n // root class must be in BisCore so should be loaded since biscore classes will never get this\n // generated implementation\n const normalizeClassName = (clsName: string) => clsName.replace(\".\", \":\");\n const rootClass = ClassRegistry.findRegisteredClass(normalizeClassName(rootClassMetaData));\n assert(rootClass, `The root class for ${prop.relationshipClass} was not in BisCore.`);\n return { name, concreteEntityType: EntityReferences.typeFromClass(rootClass) };\n });\n\n Object.defineProperty(\n generatedClass.prototype,\n \"collectReferenceIds\",\n {\n value(this: typeof generatedClass, referenceIds: EntityReferenceSet) {\n // eslint-disable-next-line @typescript-eslint/dot-notation\n const superImpl = superclass.prototype[\"collectReferenceIds\"];\n superImpl.call(this, referenceIds);\n for (const navProp of navigationProps) {\n const relatedElem: RelatedElement | undefined = (this as any)[navProp.name]; // cast to any since subclass can have any extensions\n if (!relatedElem || !Id64.isValid(relatedElem.id))\n continue;\n const referenceId = EntityReferences.fromEntityType(relatedElem.id, navProp.concreteEntityType);\n referenceIds.add(referenceId);\n }\n },\n // defaults for methods on a prototype (required for sinon to stub out methods on tests)\n writable: true,\n configurable: true,\n },\n );\n }\n\n // if the schema is a proxy for a domain with behavior, throw exceptions for all protected operations\n if (schema.missingRequiredBehavior) {\n const throwError = () => {\n throw new IModelError(IModelStatus.WrongHandler, `Schema [${domainName}] not registered, but is marked with SchemaHasBehavior`);\n };\n\n superclass.protectedOperations.forEach((operation) => (generatedClass as any)[operation] = throwError);\n }\n\n iModel.jsClassMap.register(generatedClass, schema); // register it before returning\n return generatedClass;\n }\n\n /** Register all of the classes found in the given module that derive from [[Entity]].\n * [[register]] will be invoked for each subclass of `Entity` exported by `moduleObj`.\n * @param moduleObj The module to search for subclasses of Entity\n * @param schema The schema that contains all of the [ECClass]($ecschema-metadata)es exported by `moduleObj`.\n */\n public static registerModule(moduleObj: any, schema: typeof Schema) {\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\n const thisClass = moduleObj[thisMember];\n if (thisClass.prototype instanceof Entity)\n this.register(thisClass, schema);\n }\n }\n\n /**\n * This function fetches the specified Entity from the imodel, generates a JavaScript class for it, and registers the generated\n * class. This function also ensures that all of the base classes of the Entity exist and are registered.\n */\n private static generateClass(classFullName: string, iModel: IModelDb): typeof Entity {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const metadata: EntityMetaData | undefined = iModel.classMetaDataRegistry.find(classFullName);\n if (metadata === undefined || metadata.ecclass === undefined)\n throw this.makeMetaDataNotFoundError(classFullName);\n\n // Make sure we have all base classes registered.\n if (metadata.baseClasses && (0 !== metadata.baseClasses.length))\n this.getClass(metadata.baseClasses[0], iModel);\n\n // Now we can generate the class from the classDef.\n return this.generateClassForEntity(metadata, iModel);\n }\n\n /** Find a registered class by classFullName.\n * @param classFullName class to find\n * @param iModel The IModel that contains the class definitions\n * @returns The Entity class or undefined\n */\n public static findRegisteredClass(classFullName: string): typeof Entity | undefined {\n return this._globalClassMap.get(classFullName.toLowerCase());\n }\n\n /** Get the Entity class for the specified Entity className.\n * @param classFullName The full BIS class name of the Entity\n * @param iModel The IModel that contains the class definitions\n * @returns The Entity class\n */\n public static getClass(classFullName: string, iModel: IModelDb): typeof Entity {\n const key = classFullName.toLowerCase();\n return iModel.jsClassMap.get(key) ?? this._globalClassMap.get(key) ?? this.generateClass(key, iModel);\n }\n\n /** Unregister a class, by name, if one is already registered.\n * This function is not normally needed, but is useful for cases where a generated *proxy* class needs to be replaced by the *real* class.\n * @param classFullName Name of the class to unregister\n * @return true if the class was unregistered\n * @internal\n */\n public static unregisterClass(classFullName: string) { return this._globalClassMap.delete(classFullName.toLowerCase()); }\n\n /** Unregister all classes from a schema.\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\n * @param schema Name of the schema to unregister\n * @internal\n */\n public static unregisterClassesFrom(schema: typeof Schema) {\n for (const entry of Array.from(this._globalClassMap)) {\n if (entry[1].schema === schema)\n this.unregisterClass(entry[0]);\n }\n }\n}\n\n/**\n * A cache that records the mapping between class names and class metadata.\n * @see [[IModelDb.classMetaDataRegistry]] to access the registry for a specific iModel.\n * @internal\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Please use `schemaContext` from the `iModel` instead.\n *\n * @example\n * @\n * Current Usage:\n * ```ts\n * const metaData: EntityMetaData | undefined = iModel.classMetaDataRegistry.find(\"SchemaName:ClassName\");\n * ```\n *\n * Replacement:\n * ```ts\n * const entityMetaData: EntityClass | undefined = iModel.schemaContext.getSchemaItemSync(\"SchemaName.ClassName\", EntityClass);\n * const relationshipMetaData: RelationshipClass | undefined = iModel.schemaContext.getSchemaItemSync(\"SchemaName\", \"ClassName\", RelationshipClass);\n * ```\n */\nexport class MetaDataRegistry {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n private _registry = new Map<string, EntityMetaData>();\n private _classIdToName = new Map<Id64String, string>();\n\n /** Get the specified Entity metadata */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public find(classFullName: string): EntityMetaData | undefined {\n return this._registry.get(classFullName.toLowerCase());\n }\n\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public findByClassId(classId: Id64String): EntityMetaData | undefined {\n const name = this._classIdToName.get(classId);\n return undefined !== name ? this.find(name) : undefined;\n }\n\n /** Add metadata to the cache */\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n public add(classFullName: string, metaData: EntityMetaData): void {\n const name = classFullName.toLowerCase();\n this._registry.set(name, metaData);\n this._classIdToName.set(metaData.classId, name);\n }\n}\n"]}
|
package/lib/cjs/IModelDb.js
CHANGED
|
@@ -1858,7 +1858,7 @@ function processSchemaWriteStatus(status) {
|
|
|
1858
1858
|
const element = this.tryGetElement(elementId, elementClass);
|
|
1859
1859
|
if (undefined === element) {
|
|
1860
1860
|
if (typeof elementId === "string" || elementId instanceof core_common_1.Code)
|
|
1861
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `Element=${elementId}`);
|
|
1861
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `Element=${elementId.toString()}`);
|
|
1862
1862
|
else
|
|
1863
1863
|
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, `Element={id: ${elementId.id} federationGuid: ${elementId.federationGuid}, code={spec: ${elementId.code?.spec}, scope: ${elementId.code?.scope}, value: ${elementId.code?.value}}}`);
|
|
1864
1864
|
}
|