@itwin/imodel-transformer 1.2.1-dev.0 → 1.2.1-dev.2
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/IModelExporter.d.ts +18 -0
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +221 -16
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +5 -1
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/package.json +1 -1
|
@@ -389,6 +389,7 @@ export declare class ChangedInstanceIds {
|
|
|
389
389
|
* @param change ChangedECInstance which has the ECInstanceId, changeType (insert, update, delete) and ECClassId of the changed entity
|
|
390
390
|
*/
|
|
391
391
|
addChange(change: ChangedECInstance): Promise<void>;
|
|
392
|
+
addChangeKey(change: ChangeInstanceKey): Promise<void>;
|
|
392
393
|
/**
|
|
393
394
|
* This method should only be called inside [[IModelTransformer.addCustomChanges]].
|
|
394
395
|
* It adds the provided change to the element changes maintained by this instance of ChangedInstanceIds.
|
|
@@ -438,4 +439,21 @@ export declare class ChangedInstanceIds {
|
|
|
438
439
|
*/
|
|
439
440
|
static initialize(opts: ChangedInstanceIdsInitOptions): Promise<ChangedInstanceIds | undefined>;
|
|
440
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Represents a changed instance key extracted from a changeset.
|
|
444
|
+
* @internal
|
|
445
|
+
*/
|
|
446
|
+
interface ChangeInstanceKey {
|
|
447
|
+
/** The ECInstanceId of the changed instance */
|
|
448
|
+
instanceId: Id64String;
|
|
449
|
+
/** The ECClassId of the changed instance. May be undefined if not available from the changeset. */
|
|
450
|
+
classId?: Id64String;
|
|
451
|
+
/** Indicates if the instance ID was reused (i.e., ClassId changed during an update operation) */
|
|
452
|
+
isIdReused?: true;
|
|
453
|
+
/** The type of change operation performed on the instance */
|
|
454
|
+
op: SqliteChangeOp;
|
|
455
|
+
/** The name of the ECDb table containing the changed instance */
|
|
456
|
+
tableName: string;
|
|
457
|
+
}
|
|
458
|
+
export {};
|
|
441
459
|
//# sourceMappingURL=IModelExporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,WAAW,EAEX,iBAAiB,
|
|
1
|
+
{"version":3,"file":"IModelExporter.d.ts","sourceRoot":"","sources":["../../src/IModelExporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,WAAW,EAEX,iBAAiB,EAIjB,OAAO,EACP,aAAa,EACb,kBAAkB,EAElB,mBAAmB,EAEnB,QAAQ,EAER,cAAc,EACd,KAAK,EAEL,YAAY,EACZ,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,OAAO,EAEP,UAAU,EAIX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,SAAS,EAIV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,MAAM,EACN,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AAKxC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C,CAAC;;;GAGC,GAAG,CACF;IAAE,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE;AACvC;;;;;GAKG;GACD;IAAE,kBAAkB,EAAE,kBAAkB,CAAA;CAAE;AAC5C;;;GAGG;GACD;IAA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sB,CACjC,UAAU,EAAE,cAAc,EAC1B,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;;;;;;;OAUG;IACU,oBAAoB,CAC/B,UAAU,EAAE,cAAc,EAC1B,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC;IAQhB;;;;;;;;OAQG;IACI,qBAAqB,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAM5E;;;OAGG;YACW,yBAAyB;YA4BzB,kCAAkC;YAgBlC,4BAA4B;IAc1C,OAAO,CAAC,YAAY;IAyBpB;;;OAGG;WACiB,UAAU,CAC5B,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;CA2D3C;AAWD;;;GAGG;AACH,UAAU,iBAAiB;IACzB,+CAA+C;IAC/C,UAAU,EAAE,UAAU,CAAC;IACvB,mGAAmG;IACnG,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,iGAAiG;IACjG,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,6DAA6D;IAC7D,EAAE,EAAE,cAAc,CAAC;IACnB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -861,6 +861,26 @@ class ChangedInstanceIds {
|
|
|
861
861
|
else if (this.isElement(ecClassId))
|
|
862
862
|
this.handleChange(this.element, changeType, change.ECInstanceId);
|
|
863
863
|
}
|
|
864
|
+
async addChangeKey(change) {
|
|
865
|
+
if (!this._ecClassIdsInitialized)
|
|
866
|
+
await this.setupECClassIds();
|
|
867
|
+
const ecClassId = change.classId;
|
|
868
|
+
if (ecClassId === undefined)
|
|
869
|
+
throw new Error(`ECClassId was not found for id: ${change.instanceId}! Table is : ${change.tableName}`);
|
|
870
|
+
const changeType = change.op;
|
|
871
|
+
if (this._relationshipSubclassIdsToSkip?.has(ecClassId))
|
|
872
|
+
return;
|
|
873
|
+
if (this.isRelationship(ecClassId))
|
|
874
|
+
this.handleChange(this.relationship, changeType, change.instanceId);
|
|
875
|
+
else if (this.isCodeSpec(ecClassId))
|
|
876
|
+
this.handleChange(this.codeSpec, changeType, change.instanceId);
|
|
877
|
+
else if (this.isAspect(ecClassId))
|
|
878
|
+
this.handleChange(this.aspect, changeType, change.instanceId);
|
|
879
|
+
else if (this.isModel(ecClassId))
|
|
880
|
+
this.handleChange(this.model, changeType, change.instanceId);
|
|
881
|
+
else if (this.isElement(ecClassId))
|
|
882
|
+
this.handleChange(this.element, changeType, change.instanceId);
|
|
883
|
+
}
|
|
864
884
|
/**
|
|
865
885
|
* This method should only be called inside [[IModelTransformer.addCustomChanges]].
|
|
866
886
|
* It adds the provided change to the element changes maintained by this instance of ChangedInstanceIds.
|
|
@@ -1046,25 +1066,210 @@ class ChangedInstanceIds {
|
|
|
1046
1066
|
if (csFileProps === undefined)
|
|
1047
1067
|
return undefined;
|
|
1048
1068
|
const changedInstanceIds = new ChangedInstanceIds(opts.iModel);
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1069
|
+
const processor = new ChangesetProcessor(opts.iModel);
|
|
1070
|
+
// row will be skip could cause some other issue.
|
|
1071
|
+
processor.setActionForWhenIdReuseDetected("Skip");
|
|
1072
|
+
await processor.processFiles(csFileProps, changedInstanceIds);
|
|
1073
|
+
return changedInstanceIds;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
exports.ChangedInstanceIds = ChangedInstanceIds;
|
|
1077
|
+
/**
|
|
1078
|
+
* Processes changesets to extract changed instance information.
|
|
1079
|
+
* This class reads changeset files and populates a ChangedInstanceIds object with the changes.
|
|
1080
|
+
* @internal
|
|
1081
|
+
*/
|
|
1082
|
+
class ChangesetProcessor {
|
|
1083
|
+
constructor(db) {
|
|
1084
|
+
this.db = db;
|
|
1085
|
+
this._cacheTables = new Map();
|
|
1086
|
+
this._onIdReuseDetected = "Fail";
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Sets the action to take when ID reuse is detected during changeset processing.
|
|
1090
|
+
* @param value The action to take - either "Skip" to ignore reused IDs or "Fail" to throw an error.
|
|
1091
|
+
* @remarks ID reuse occurs when an ECInstanceId is deleted and then reinserted with a different ECClassId.
|
|
1092
|
+
* The default behavior is "Fail" which logs an error when ID reuse is detected.
|
|
1093
|
+
*/
|
|
1094
|
+
setActionForWhenIdReuseDetected(value) {
|
|
1095
|
+
this._onIdReuseDetected = value;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Processes multiple changeset files sequentially.
|
|
1099
|
+
* @param csFileProps Array of changeset file properties to process.
|
|
1100
|
+
* @param store The ChangedInstanceIds object to populate with extracted changes.
|
|
1101
|
+
*/
|
|
1102
|
+
async processFiles(csFileProps, store) {
|
|
1103
|
+
for (const csFileProp of csFileProps) {
|
|
1104
|
+
await this.processFile(csFileProp, store);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Processes a single changeset file and extracts changed instance information.
|
|
1109
|
+
* @param csFileProp The changeset file properties.
|
|
1110
|
+
* @param store The ChangedInstanceIds object to populate with extracted changes.
|
|
1111
|
+
* @remarks This method reads through the changeset file, processes each row, and adds valid changes
|
|
1112
|
+
* to the store. Duplicate changes (based on instanceId and classId) are skipped, and rows where
|
|
1113
|
+
* the ClassId was reused are also filtered out.
|
|
1114
|
+
*/
|
|
1115
|
+
async processFile(csFileProp, store) {
|
|
1116
|
+
const instanceKeySet = new Set();
|
|
1117
|
+
const makeKey = (val) => `${val.instanceId}-${val.classId}`;
|
|
1118
|
+
const csReader = core_backend_1.SqliteChangesetReader.openFile({
|
|
1119
|
+
fileName: csFileProp.pathname,
|
|
1120
|
+
db: this.db,
|
|
1121
|
+
disableSchemaCheck: true,
|
|
1122
|
+
});
|
|
1123
|
+
try {
|
|
1124
|
+
while (csReader.step()) {
|
|
1125
|
+
const row = this.processRow(csReader);
|
|
1126
|
+
// SKIP over row where ClassId was reused
|
|
1127
|
+
if (row) {
|
|
1128
|
+
if (row.isIdReused)
|
|
1129
|
+
if (this._onIdReuseDetected === "Fail") {
|
|
1130
|
+
throw new Error(`ClassId changed during update for instance ${row.instanceId}`);
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
continue;
|
|
1134
|
+
}
|
|
1135
|
+
const key = makeKey(row);
|
|
1136
|
+
if (!instanceKeySet.has(key)) {
|
|
1137
|
+
instanceKeySet.add(key);
|
|
1138
|
+
await store.addChangeKey(row);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1063
1141
|
}
|
|
1142
|
+
}
|
|
1143
|
+
finally {
|
|
1064
1144
|
csReader.close();
|
|
1065
1145
|
}
|
|
1066
|
-
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Processes a single row from the changeset reader and extracts change information.
|
|
1149
|
+
* @param reader The SqliteChangesetReader positioned at the current row.
|
|
1150
|
+
* @returns A ChangeInstanceKey object containing the extracted change information, or undefined
|
|
1151
|
+
* if the row should be skipped (e.g., system tables, invalid primary keys).
|
|
1152
|
+
* @remarks This method handles special cases such as virtual ClassId columns, ClassId changes
|
|
1153
|
+
* during updates (ID reuse), and falls back to querying the database when ClassId is not
|
|
1154
|
+
* available in the changeset.
|
|
1155
|
+
*/
|
|
1156
|
+
processRow(reader) {
|
|
1157
|
+
const tableName = reader.tableName;
|
|
1158
|
+
if (tableName.startsWith("ec_") ||
|
|
1159
|
+
tableName.startsWith("be_") ||
|
|
1160
|
+
tableName.startsWith("dgn_"))
|
|
1161
|
+
return;
|
|
1162
|
+
const tableInfo = this.getTable(tableName);
|
|
1163
|
+
if (!tableInfo) {
|
|
1164
|
+
return undefined;
|
|
1165
|
+
}
|
|
1166
|
+
const pks = reader.primaryKeyValues;
|
|
1167
|
+
if (pks.length !== 1)
|
|
1168
|
+
return undefined;
|
|
1169
|
+
const instanceId = reader.primaryKeyValues[0];
|
|
1170
|
+
const kClassIdColumnIndex = 1;
|
|
1171
|
+
let classId;
|
|
1172
|
+
let isIdReused;
|
|
1173
|
+
if (tableInfo.isClassIdVirtual) {
|
|
1174
|
+
classId = tableInfo.exclusiveRootClassId;
|
|
1175
|
+
}
|
|
1176
|
+
else {
|
|
1177
|
+
if (reader.op === "Updated") {
|
|
1178
|
+
const oldClassId = reader.getChangeValueId(kClassIdColumnIndex, "Old");
|
|
1179
|
+
const newClassId = reader.getChangeValueId(kClassIdColumnIndex, "New");
|
|
1180
|
+
if (oldClassId !== newClassId) {
|
|
1181
|
+
core_bentley_1.Logger.logError(loggerCategory, `ClassId changed during update for instance ${instanceId}`);
|
|
1182
|
+
isIdReused = true;
|
|
1183
|
+
}
|
|
1184
|
+
classId =
|
|
1185
|
+
newClassId ||
|
|
1186
|
+
oldClassId ||
|
|
1187
|
+
this.getClassIdFromDb(reader.tableName, instanceId);
|
|
1188
|
+
}
|
|
1189
|
+
else if (reader.op === "Inserted") {
|
|
1190
|
+
classId = reader.getChangeValueId(kClassIdColumnIndex, "New");
|
|
1191
|
+
}
|
|
1192
|
+
else if (reader.op === "Deleted") {
|
|
1193
|
+
classId = reader.getChangeValueId(kClassIdColumnIndex, "Old");
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
return {
|
|
1197
|
+
instanceId,
|
|
1198
|
+
classId,
|
|
1199
|
+
op: reader.op,
|
|
1200
|
+
isIdReused,
|
|
1201
|
+
tableName,
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Retrieves the ECClassId for a given instance directly from the database.
|
|
1206
|
+
* @param tableName The name of the table containing the instance.
|
|
1207
|
+
* @param instanceId The ECInstanceId to look up.
|
|
1208
|
+
* @returns The ECClassId if found, undefined otherwise.
|
|
1209
|
+
* @remarks This is used as a fallback when the ClassId cannot be determined from the changeset itself.
|
|
1210
|
+
*/
|
|
1211
|
+
getClassIdFromDb(tableName, instanceId) {
|
|
1212
|
+
try {
|
|
1213
|
+
return this.db?.withPreparedSqliteStatement(`SELECT [ECClassId] FROM [${tableName}] WHERE [rowId]=?`, (stmt) => {
|
|
1214
|
+
stmt.bindId(1, instanceId);
|
|
1215
|
+
return stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW
|
|
1216
|
+
? stmt.getValueId(0)
|
|
1217
|
+
: undefined;
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
catch {
|
|
1221
|
+
return undefined;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Retrieves table metadata from the ECDb schema tables.
|
|
1226
|
+
* @param tableName The name of the table to look up.
|
|
1227
|
+
* @returns TableInfo containing the table's exclusive root class ID and whether ClassId is virtual,
|
|
1228
|
+
* or undefined if the table is not found.
|
|
1229
|
+
* @remarks Results are cached to avoid repeated database queries for the same table.
|
|
1230
|
+
* The exclusive root class ID is used for tables with virtual ClassId columns where all instances
|
|
1231
|
+
* share the same class.
|
|
1232
|
+
*/
|
|
1233
|
+
getTable(tableName) {
|
|
1234
|
+
if (this._cacheTables.has(tableName))
|
|
1235
|
+
return this._cacheTables.get(tableName);
|
|
1236
|
+
const sql = `
|
|
1237
|
+
SELECT
|
|
1238
|
+
JSON_OBJECT (
|
|
1239
|
+
'exclusiveRootClassId', FORMAT ('0x%x',
|
|
1240
|
+
COALESCE (
|
|
1241
|
+
[t].[ExclusiveRootClassId], (
|
|
1242
|
+
SELECT [parent].[ExclusiveRootClassId]
|
|
1243
|
+
FROM [ec_Table] [parent]
|
|
1244
|
+
WHERE [parent].[Id] = [t].[ParentTableId] AND [parent].[Type] = 1))),
|
|
1245
|
+
'isClassIdVirtual', (
|
|
1246
|
+
SELECT
|
|
1247
|
+
[c].[IsVirtual]
|
|
1248
|
+
FROM
|
|
1249
|
+
[ec_Column] [c]
|
|
1250
|
+
WHERE
|
|
1251
|
+
[c].[Name] = 'ECClassId' AND [c].[TableId] = [t].[Id]
|
|
1252
|
+
)
|
|
1253
|
+
)
|
|
1254
|
+
FROM [ec_Table] [t]
|
|
1255
|
+
WHERE
|
|
1256
|
+
[t].[Name] = ?;
|
|
1257
|
+
`;
|
|
1258
|
+
return this.db.withPreparedSqliteStatement(sql, (stmt) => {
|
|
1259
|
+
stmt.bindString(1, tableName);
|
|
1260
|
+
if (stmt.step() === core_bentley_1.DbResult.BE_SQLITE_ROW) {
|
|
1261
|
+
const table = JSON.parse(stmt.getValueString(0), (key, value) => {
|
|
1262
|
+
if (value === null)
|
|
1263
|
+
return undefined;
|
|
1264
|
+
if (key === "isClassIdVirtual")
|
|
1265
|
+
return value === 0 ? false : true;
|
|
1266
|
+
return value;
|
|
1267
|
+
});
|
|
1268
|
+
this._cacheTables.set(tableName, table);
|
|
1269
|
+
return table;
|
|
1270
|
+
}
|
|
1271
|
+
return undefined;
|
|
1272
|
+
});
|
|
1067
1273
|
}
|
|
1068
1274
|
}
|
|
1069
|
-
exports.ChangedInstanceIds = ChangedInstanceIds;
|
|
1070
1275
|
//# sourceMappingURL=IModelExporter.js.map
|