@itwin/core-backend 5.6.0-dev.14 → 5.6.0-dev.16

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.
@@ -184,6 +184,18 @@ class TestIModel {
184
184
  HubMock.shutdown();
185
185
  }
186
186
  }
187
+ const removePropertyRecursive = (obj, prop) => {
188
+ if (obj && typeof obj === "object") {
189
+ Object.keys(obj).forEach((key) => {
190
+ if (key === prop) {
191
+ delete obj[key];
192
+ }
193
+ else {
194
+ removePropertyRecursive(obj[key], prop);
195
+ }
196
+ });
197
+ }
198
+ };
187
199
  describe("rebase changes & stashing api", function () {
188
200
  let testIModel;
189
201
  before(async () => {
@@ -483,7 +495,7 @@ describe("rebase changes & stashing api", function () {
483
495
  b1.saveChanges();
484
496
  await chai.expect(b1.txns.withIndirectTxnModeAsync(async () => {
485
497
  await b1.pushChanges({ description: "test" });
486
- })).to.be.rejectedWith("Cannot push changeset while in an indirect change scope");
498
+ })).to.be.rejectedWith("Cannot pull and apply changeset while in an indirect change scope");
487
499
  await b1.pushChanges({ description: "test" });
488
500
  });
489
501
  it("should fail to saveFileProperty/deleteFileProperty in indirect scope", async () => {
@@ -978,7 +990,7 @@ describe("rebase changes & stashing api", function () {
978
990
  onRebase: {
979
991
  beginCount: 0,
980
992
  endCount: 0,
981
- beginIds: [],
993
+ beginTxns: [],
982
994
  },
983
995
  onRebaseTxn: {
984
996
  beginTxns: [],
@@ -987,44 +999,174 @@ describe("rebase changes & stashing api", function () {
987
999
  rebaseHandler: {
988
1000
  shouldReinstate: [],
989
1001
  recompute: [],
990
- }
1002
+ },
1003
+ pullMerge: {
1004
+ beginCount: 0,
1005
+ endCount: 0,
1006
+ beginChangeset: [],
1007
+ endChangeset: [],
1008
+ },
1009
+ applyIncomingChanges: {
1010
+ beginCount: 0,
1011
+ endCount: 0,
1012
+ beginChangesets: [],
1013
+ endChangesets: [],
1014
+ },
1015
+ reverseLocalChanges: {
1016
+ beginCount: 0,
1017
+ endCount: 0,
1018
+ txns: [],
1019
+ },
1020
+ downloadChangesets: {
1021
+ beginCount: 0,
1022
+ endCount: 0,
1023
+ },
991
1024
  };
992
1025
  const resetEvent = () => {
993
1026
  events.onRebase.beginCount = 0;
994
1027
  events.onRebase.endCount = 0;
995
- events.onRebase.beginIds = [];
1028
+ events.onRebase.beginTxns = [];
996
1029
  events.onRebaseTxn.beginTxns = [];
997
1030
  events.onRebaseTxn.endTxns = [];
998
1031
  events.rebaseHandler.shouldReinstate = [];
999
1032
  events.rebaseHandler.recompute = [];
1033
+ events.pullMerge.beginCount = 0;
1034
+ events.pullMerge.endCount = 0;
1035
+ events.pullMerge.beginChangeset = [];
1036
+ events.pullMerge.endChangeset = [];
1037
+ events.applyIncomingChanges.beginCount = 0;
1038
+ events.applyIncomingChanges.endCount = 0;
1039
+ events.applyIncomingChanges.beginChangesets = [];
1040
+ events.applyIncomingChanges.endChangesets = [];
1041
+ events.reverseLocalChanges.beginCount = 0;
1042
+ events.reverseLocalChanges.endCount = 0;
1043
+ events.reverseLocalChanges.txns = [];
1044
+ events.downloadChangesets.beginCount = 0;
1045
+ events.downloadChangesets.endCount = 0;
1000
1046
  };
1001
- b2.txns.onRebaseBegin.addListener((ids) => {
1047
+ // onPullMergeXXXX
1048
+ b2.txns.rebaser.onPullMergeBegin.addListener((changeset) => {
1049
+ events.pullMerge.beginCount++;
1050
+ events.pullMerge.beginChangeset.push(changeset);
1051
+ });
1052
+ b2.txns.rebaser.onPullMergeEnd.addListener((changeset) => {
1053
+ events.pullMerge.endCount++;
1054
+ events.pullMerge.endChangeset.push(changeset);
1055
+ });
1056
+ // onApplyIncomingChangesXXXX
1057
+ b2.txns.rebaser.onApplyIncomingChangesBegin.addListener((changesets) => {
1058
+ events.applyIncomingChanges.beginCount++;
1059
+ events.applyIncomingChanges.beginChangesets.push(...changesets);
1060
+ });
1061
+ b2.txns.rebaser.onApplyIncomingChangesEnd.addListener((changesets) => {
1062
+ events.applyIncomingChanges.endCount++;
1063
+ events.applyIncomingChanges.endChangesets.push(...changesets);
1064
+ });
1065
+ // onReverseLocalChangesXXXX
1066
+ b2.txns.rebaser.onReverseLocalChangesBegin.addListener(() => {
1067
+ events.reverseLocalChanges.beginCount++;
1068
+ });
1069
+ b2.txns.rebaser.onReverseLocalChangesEnd.addListener((txns) => {
1070
+ events.reverseLocalChanges.endCount++;
1071
+ removePropertyRecursive(txns, "timestamp"); // it changes on each run, so remove it for comparison
1072
+ events.reverseLocalChanges.txns.push(...txns);
1073
+ });
1074
+ // onDownloadChangesetsXXXX
1075
+ b2.txns.rebaser.onDownloadChangesetsBegin.addListener(() => {
1076
+ events.downloadChangesets.beginCount++;
1077
+ });
1078
+ b2.txns.rebaser.onDownloadChangesetsEnd.addListener(() => {
1079
+ events.downloadChangesets.endCount++;
1080
+ });
1081
+ // onRebaseXXXX
1082
+ b2.txns.rebaser.onRebaseBegin.addListener((txns) => {
1002
1083
  events.onRebase.beginCount++;
1003
- events.onRebase.beginIds.push(...ids);
1084
+ removePropertyRecursive(txns, "timestamp"); // it changes on each run, so remove it for comparison
1085
+ events.onRebase.beginTxns.push(...txns);
1004
1086
  });
1005
- b2.txns.onRebaseEnd.addListener(() => {
1087
+ b2.txns.rebaser.onRebaseEnd.addListener(() => {
1006
1088
  events.onRebase.endCount++;
1007
1089
  });
1008
- b2.txns.onRebaseTxnBegin.addListener((txn) => {
1090
+ // onRebaseTxnXXXX
1091
+ b2.txns.rebaser.onRebaseTxnBegin.addListener((txn) => {
1092
+ removePropertyRecursive(txn, "timestamp"); // it changes on each run, so remove it for comparison
1009
1093
  events.onRebaseTxn.beginTxns.push(txn);
1010
1094
  });
1011
- b2.txns.onRebaseTxnEnd.addListener((txn) => {
1095
+ b2.txns.rebaser.onRebaseTxnEnd.addListener((txn) => {
1096
+ removePropertyRecursive(txn, "timestamp"); // it changes on each run, so remove it for comparison
1012
1097
  events.onRebaseTxn.endTxns.push(txn);
1013
1098
  });
1014
1099
  b2.txns.rebaser.setCustomHandler({
1015
1100
  shouldReinstate: (_txn) => {
1101
+ // shouldReinstate
1102
+ removePropertyRecursive(_txn, "timestamp"); // it changes on each run, so remove it for comparison
1016
1103
  events.rebaseHandler.shouldReinstate.push(_txn);
1017
1104
  return true;
1018
1105
  },
1019
1106
  recompute: async (_txn) => {
1107
+ // recompute
1108
+ removePropertyRecursive(_txn, "timestamp"); // it changes on each run, so remove it for comparison
1020
1109
  events.rebaseHandler.recompute.push(_txn);
1021
1110
  },
1022
1111
  });
1023
1112
  resetEvent();
1024
1113
  await b2.pullChanges();
1114
+ // pullMerge events
1115
+ chai.expect(events.pullMerge.beginCount).to.equal(1);
1116
+ chai.expect(events.pullMerge.endCount).to.equal(1);
1117
+ chai.expect((events.pullMerge.beginChangeset[0].index)).to.equal(3);
1118
+ chai.expect((events.pullMerge.endChangeset[0].index)).to.equal(4);
1119
+ // applyIncomingChanges events
1120
+ chai.expect(events.applyIncomingChanges.beginCount).to.equal(1);
1121
+ chai.expect(events.applyIncomingChanges.endCount).to.equal(1);
1122
+ chai.expect(events.applyIncomingChanges.beginChangesets.map((cs) => cs.index)).to.deep.equal([4]);
1123
+ chai.expect(events.applyIncomingChanges.endChangesets.map((cs) => cs.index)).to.deep.equal([4]);
1124
+ // downloadChangesets events
1125
+ chai.expect(events.downloadChangesets.beginCount).to.equal(1);
1126
+ chai.expect(events.downloadChangesets.endCount).to.equal(1);
1127
+ // reverseLocalChanges events
1128
+ chai.expect(events.reverseLocalChanges.beginCount).to.equal(1);
1129
+ chai.expect(events.reverseLocalChanges.endCount).to.equal(1);
1130
+ chai.expect(events.reverseLocalChanges.txns.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002"]);
1131
+ // rebase events
1025
1132
  chai.expect(events.onRebase.beginCount).to.equal(1);
1026
1133
  chai.expect(events.onRebase.endCount).to.equal(1);
1027
- chai.expect(events.onRebase.beginIds).to.deep.equal(["0x100000000", "0x100000001", "0x100000002"]);
1134
+ chai.expect(events.onRebase.beginTxns).to.deep.equal([
1135
+ {
1136
+ grouped: false,
1137
+ id: "0x100000000",
1138
+ nextId: "0x100000001",
1139
+ props: {
1140
+ description: "first change"
1141
+ },
1142
+ reversed: true,
1143
+ sessionId: 1,
1144
+ type: "Data"
1145
+ },
1146
+ {
1147
+ grouped: false,
1148
+ id: "0x100000001",
1149
+ nextId: "0x100000002",
1150
+ prevId: "0x100000000",
1151
+ props: {
1152
+ description: "second change",
1153
+ },
1154
+ reversed: true,
1155
+ sessionId: 1,
1156
+ type: "Data"
1157
+ },
1158
+ {
1159
+ grouped: false,
1160
+ id: "0x100000002",
1161
+ prevId: "0x100000001",
1162
+ props: {
1163
+ description: "third change"
1164
+ },
1165
+ reversed: true,
1166
+ sessionId: 1,
1167
+ type: "Data"
1168
+ }
1169
+ ]);
1028
1170
  chai.expect(events.onRebaseTxn.beginTxns.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002"]);
1029
1171
  chai.expect(events.onRebaseTxn.endTxns.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002"]);
1030
1172
  chai.expect(events.rebaseHandler.shouldReinstate.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002"]);
@@ -1035,12 +1177,59 @@ describe("rebase changes & stashing api", function () {
1035
1177
  await b1.pushChanges({ description: "update element 1 direct and 1 indirect" });
1036
1178
  await testIModel.insertElement(b2);
1037
1179
  await testIModel.insertElement(b2, true);
1038
- b2.saveChanges("forth change");
1180
+ b2.saveChanges("fourth change");
1039
1181
  resetEvent();
1040
1182
  await b2.pullChanges();
1041
1183
  chai.expect(events.onRebase.beginCount).to.equal(1);
1042
1184
  chai.expect(events.onRebase.endCount).to.equal(1);
1043
- chai.expect(events.onRebase.beginIds).to.deep.equal(["0x100000000", "0x100000001", "0x100000002", "0x100000003"]);
1185
+ chai.expect(events.onRebase.beginTxns).to.deep.equal([
1186
+ {
1187
+ grouped: false,
1188
+ id: "0x100000000",
1189
+ nextId: "0x100000001",
1190
+ props: {
1191
+ description: "first change"
1192
+ },
1193
+ reversed: true,
1194
+ sessionId: 1,
1195
+ type: "Data"
1196
+ },
1197
+ {
1198
+ grouped: false,
1199
+ id: "0x100000001",
1200
+ nextId: "0x100000002",
1201
+ prevId: "0x100000000",
1202
+ props: {
1203
+ description: "second change"
1204
+ },
1205
+ reversed: true,
1206
+ sessionId: 1,
1207
+ type: "Data"
1208
+ },
1209
+ {
1210
+ grouped: false,
1211
+ id: "0x100000002",
1212
+ nextId: "0x100000003",
1213
+ prevId: "0x100000001",
1214
+ props: {
1215
+ description: "third change"
1216
+ },
1217
+ reversed: true,
1218
+ sessionId: 1,
1219
+ type: "Data"
1220
+ },
1221
+ {
1222
+ grouped: false,
1223
+ id: "0x100000003",
1224
+ prevId: "0x100000002",
1225
+ props: {
1226
+ description: "fourth change"
1227
+ },
1228
+ reversed: true,
1229
+ sessionId: 1,
1230
+ type: "Data"
1231
+ }
1232
+ ]);
1044
1233
  chai.expect(events.onRebaseTxn.beginTxns.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002", "0x100000003"]);
1045
1234
  chai.expect(events.onRebaseTxn.endTxns.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002", "0x100000003"]);
1046
1235
  chai.expect(events.rebaseHandler.shouldReinstate.map((txn) => txn.id)).to.deep.equal(["0x100000000", "0x100000001", "0x100000002", "0x100000003"]);