@itwin/core-backend 5.10.0-dev.16 → 5.10.0-dev.19

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.
Files changed (41) hide show
  1. package/lib/cjs/ChangesetReader.d.ts +84 -1
  2. package/lib/cjs/ChangesetReader.d.ts.map +1 -1
  3. package/lib/cjs/ChangesetReader.js +108 -12
  4. package/lib/cjs/ChangesetReader.js.map +1 -1
  5. package/lib/cjs/TxnManager.d.ts.map +1 -1
  6. package/lib/cjs/TxnManager.js +7 -0
  7. package/lib/cjs/TxnManager.js.map +1 -1
  8. package/lib/cjs/internal/ElementLRUCache.d.ts.map +1 -1
  9. package/lib/cjs/internal/ElementLRUCache.js +23 -4
  10. package/lib/cjs/internal/ElementLRUCache.js.map +1 -1
  11. package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -1
  12. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +54 -9
  13. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -1
  14. package/lib/cjs/workspace/SettingsSchemas.d.ts +15 -1
  15. package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
  16. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  17. package/lib/esm/ChangesetReader.d.ts +84 -1
  18. package/lib/esm/ChangesetReader.d.ts.map +1 -1
  19. package/lib/esm/ChangesetReader.js +108 -12
  20. package/lib/esm/ChangesetReader.js.map +1 -1
  21. package/lib/esm/TxnManager.d.ts.map +1 -1
  22. package/lib/esm/TxnManager.js +7 -0
  23. package/lib/esm/TxnManager.js.map +1 -1
  24. package/lib/esm/internal/ElementLRUCache.d.ts.map +1 -1
  25. package/lib/esm/internal/ElementLRUCache.js +23 -4
  26. package/lib/esm/internal/ElementLRUCache.js.map +1 -1
  27. package/lib/esm/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -1
  28. package/lib/esm/internal/workspace/SettingsSchemasImpl.js +54 -9
  29. package/lib/esm/internal/workspace/SettingsSchemasImpl.js.map +1 -1
  30. package/lib/esm/test/ElementLRUCache.test.js +60 -0
  31. package/lib/esm/test/ElementLRUCache.test.js.map +1 -1
  32. package/lib/esm/test/imodel/IModel.test.js +29 -0
  33. package/lib/esm/test/imodel/IModel.test.js.map +1 -1
  34. package/lib/esm/test/standalone/ChangesetReader.test.js +945 -337
  35. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  36. package/lib/esm/test/standalone/SettingsSchemas.test.js +382 -0
  37. package/lib/esm/test/standalone/SettingsSchemas.test.js.map +1 -1
  38. package/lib/esm/workspace/SettingsSchemas.d.ts +15 -1
  39. package/lib/esm/workspace/SettingsSchemas.d.ts.map +1 -1
  40. package/lib/esm/workspace/SettingsSchemas.js.map +1 -1
  41. package/package.json +14 -14
@@ -21,6 +21,7 @@ import { AnyDb, SqliteChangeOp } from "./SqliteChangesetReader";
21
21
  * @beta
22
22
  */
23
23
  export declare class ChangesetReader implements Disposable, ChangeSource {
24
+ private static readonly defaultSpillThresholdInBytes;
24
25
  private readonly _nativeReader;
25
26
  private _rowOptions?;
26
27
  private _propFilter;
@@ -34,18 +35,21 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
34
35
  /**
35
36
  * `true` when the current row belongs to an EC-mapped table.
36
37
  * Valid only after a successful call to [[step]].
38
+ * @throws [[IModelError]] if called before a successful [[step]] call.
37
39
  * @beta
38
40
  */
39
41
  get isECTable(): boolean;
40
42
  /**
41
43
  * Name of the SQLite table for the current change row.
42
44
  * Valid only after a successful call to [[step]].
45
+ * @throws [[IModelError]] if called before a successful [[step]] call.
43
46
  * @beta
44
47
  */
45
48
  get tableName(): string;
46
49
  /**
47
50
  * `true` when the current change was applied indirectly
48
51
  * Valid only after a successful call to [[step]].
52
+ * @throws [[IModelError]] if called before a successful [[step]] call.
49
53
  * @beta
50
54
  */
51
55
  get isIndirectChange(): boolean;
@@ -72,6 +76,7 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
72
76
  * @param args.invert When `true`, invert all operations (Insert↔Delete).
73
77
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
74
78
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
79
+ * @throws if the native layer fails to open the file.
75
80
  * @beta
76
81
  */
77
82
  static openFile(args: {
@@ -83,10 +88,17 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
83
88
  * @param args.db Database with schema at or ahead of the last changeset.
84
89
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
85
90
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
91
+ * @param args.spillThresholdInBytes When the total size of the changeset data in the change group exceeds this threshold (in bytes),
92
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
93
+ * This keeps peak memory usage bounded, making the API suitable for processing large changeset groups under low-memory conditions.
94
+ * Defaults to 50 MiB.
95
+ * @throws if `changesetFiles` is empty, or if the native layer fails to open
96
+ * the group.
86
97
  * @beta
87
98
  */
88
99
  static openGroup(args: {
89
100
  readonly changesetFiles: string[];
101
+ spillThresholdInBytes?: number;
90
102
  } & ChangesetReaderArgs): ChangesetReader;
91
103
  /**
92
104
  * Read pending (not yet pushed) local changes from an open IModelDb.
@@ -94,21 +106,34 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
94
106
  * @param args.includeInMemoryChanges Also include in-memory (not yet saved to disk) changes.
95
107
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
96
108
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
109
+ * @param args.spillThresholdInBytes When the total size of all local un-pushed saved changes exceeds this threshold (in bytes),
110
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
111
+ * This keeps peak memory usage bounded, making the API suitable for iModels with large local change backlogs under low-memory conditions.
112
+ * Defaults to 50 MiB.
113
+ * @throws if the native layer
114
+ * fails to open the local changes.
97
115
  * @beta
98
116
  */
99
117
  static openLocalChanges(args: Omit<ChangesetReaderArgs, "db"> & {
100
118
  db: IModelDb;
101
119
  includeInMemoryChanges?: boolean;
120
+ spillThresholdInBytes?: number;
102
121
  }): ChangesetReader;
103
122
  /**
104
123
  * Read the in-memory (not yet saved to disk) changes of an open IModelDb.
105
124
  * @param args.db Must be an [IModelDb]($backend).
106
125
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
107
126
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
127
+ * @param args.spillThresholdInBytes When the total size of the in-memory (unsaved) change data exceeds this threshold (in bytes),
128
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
129
+ * This keeps peak memory usage bounded, making the API suitable for large in-memory transactions under low-memory conditions.
130
+ * Defaults to 50 MiB.
131
+ * @throws if the native layer encounters an error while opening the in-memory changes.
108
132
  * @beta
109
133
  */
110
134
  static openInMemoryChanges(args: Omit<ChangesetReaderArgs, "db"> & {
111
135
  db: IModelDb;
136
+ spillThresholdInBytes?: number;
112
137
  }): ChangesetReader;
113
138
  /**
114
139
  * Read a single saved transaction by its id.
@@ -116,17 +141,27 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
116
141
  * @param args.txnId The id of the saved transaction to read.
117
142
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
118
143
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
144
+ * @param args.spillThresholdInBytes When the total size of the transaction's change data exceeds this threshold (in bytes),
145
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
146
+ * This keeps peak memory usage bounded, making the API suitable for large transactions under low-memory conditions.
147
+ * Defaults to 50 MiB.
148
+ * @throws if `txnId` is not found, or
149
+ * the native layer fails to open the transaction data.
119
150
  * @beta
120
151
  */
121
152
  static openTxn(args: Omit<ChangesetReaderArgs, "db"> & {
122
153
  db: IModelDb;
123
154
  txnId: Id64String;
155
+ spillThresholdInBytes?: number;
124
156
  }): ChangesetReader;
157
+ /** Handle errors that occur while auto closing the reader if there is also an error while opening the reader */
158
+ private handleCloseErrorWhileOpening;
125
159
  /**
126
160
  * Restrict iteration to changes from the named SQLite tables.
127
161
  * That means the rows for changes from other tables will be skipped entirely and won't be visible through the reader.
128
162
  * @param tableNames SQLite table names to include.
129
163
  * Note: Table names must be provided in the correct case for proper filtering.
164
+ * @throws if the native layer encounters an error while setting the filter.
130
165
  * @beta
131
166
  */
132
167
  setTableNameFilters(tableNames: Set<string>): void;
@@ -134,6 +169,7 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
134
169
  * Restrict iteration to changes with the given operation types.
135
170
  * That means the rows for changes with other operation types will be skipped entirely and won't be visible through the reader.
136
171
  * @param ops Operations to include.
172
+ * @throws if the native layer encounters an error while setting the filter.
137
173
  * @beta
138
174
  */
139
175
  setOpCodeFilters(ops: Set<SqliteChangeOp>): void;
@@ -142,43 +178,90 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
142
178
  * That means the rows for changes from other EC classes will be skipped entirely and won't be visible through the reader.
143
179
  * @param classNames EC class names to include. The classNames should be in the full name format(i.e. "SchemaName:ClassName").
144
180
  * Note: Schema names and class names must be provided in the correct case for proper filtering. Derived classes are not automatically included, so they must be specified explicitly if needed.
181
+ * @throws if the native layer encounters an error while setting the filter.
145
182
  * @beta
146
183
  */
147
184
  setClassNameFilters(classNames: Set<string>): void;
148
185
  /**
149
186
  * Remove the table-name filters
187
+ * @throws if the native layer encounters an error.
150
188
  * @beta
151
189
  */
152
190
  clearTableNameFilters(): void;
153
191
  /**
154
192
  * Remove the op-code filters
193
+ * @throws if the native layer encounters an error.
155
194
  * @beta
156
195
  */
157
196
  clearOpCodeFilters(): void;
158
197
  /**
159
198
  * Remove the class-name filters
199
+ * @throws if the native layer encounters an error.
160
200
  * @beta
161
201
  */
162
202
  clearClassNameFilters(): void;
203
+ /**
204
+ * Enable strict mode on the reader.
205
+ *
206
+ * Strict mode affects how the reader handles a **column-count mismatch** between a change
207
+ * record and the corresponding live database table. Such a mismatch can occur when columns
208
+ * have been added to a table after the changeset was created.
209
+ *
210
+ * When strict mode is **enabled**: if the number of columns recorded in a change row differs
211
+ * from the number of columns currently present in the live table, the reader throws an error
212
+ * instead of processing that row.
213
+ *
214
+ * Use strict mode when you need to be certain that every change row is interpreted against
215
+ * exactly the schema that was in effect when the changeset was written.
216
+ *
217
+ * @see [[disableStrictMode]] — the default (lenient) behaviour.
218
+ * @throws if the native layer encounters an error.
219
+ * @beta
220
+ */
221
+ enableStrictMode(): void;
222
+ /**
223
+ * Disable strict mode on the reader (this is the default).
224
+ *
225
+ * When strict mode is **disabled**: if the number of columns recorded in a change row differs
226
+ * from the number of columns currently present in the live table, the reader takes the
227
+ * **minimum** of the two column counts and proceeds normally with that subset. This is safe
228
+ * because SQLite only ever appends new columns at the end of a table and never removes them —
229
+ * so older change records simply lack the trailing columns that were added later, and those
230
+ * missing columns are silently ignored.
231
+ *
232
+ * @see [[enableStrictMode]] — throw on column-count mismatches instead.
233
+ * @throws if the native layer encounters an error.
234
+ * @beta
235
+ */
236
+ disableStrictMode(): void;
163
237
  /**
164
238
  * Advance to the next change and populate `inserted` and/or `deleted`.
165
239
  * @returns `true` while positioned on a valid change; `false` when the stream is exhausted.
240
+ * @throws if the native layer encounters an error while reading or decoding
241
+ * the next change.
166
242
  * @beta
167
243
  */
168
244
  step(): boolean;
169
245
  /**
170
246
  * SQLite opcode of the current change.
171
247
  * Valid only after a successful call to [[step]].
248
+ * @throws [[IModelError]] if called before a successful [[step]] call.
172
249
  * @beta
173
250
  */
174
251
  get op(): SqliteChangeOp;
175
252
  /**
176
253
  * Close the reader and release all native resources.
254
+ *
255
+ * @throws if the native layer encounters an error during cleanup. Native resources
256
+ * are not fully released when this throws — check the native error
257
+ * logs for details.
177
258
  * @beta
178
259
  */
179
260
  close(): void;
180
261
  /**
181
- * Implements the `Disposable` contract — calls [[close]].
262
+ * Implements the `Disposable` contract — delegates to [[close]].
263
+ *
264
+ * @throws if the native layer fails to release its resources (re-thrown from [[close]]).
182
265
  * @beta
183
266
  */
184
267
  [Symbol.dispose](): void;
@@ -1 +1 @@
1
- {"version":3,"file":"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;;;;OAiBG;IACI,gBAAgB,IAAI,IAAI;IAI/B;;;;;;;;;;;;;OAaG;IACI,iBAAiB,IAAI,IAAI;IAQhC;;;;;;OAMG;IACI,IAAI,IAAI,OAAO;IAmEtB;;;;;OAKG;IACH,IAAW,EAAE,IAAI,cAAc,CAI9B;IAMD;;;;;;;OAOG;IACI,KAAK,IAAI,IAAI;IAWpB;;;;;OAKG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGhC"}
@@ -29,6 +29,7 @@ import { PropertyFilter } from "./ChangesetReaderTypes";
29
29
  * @beta
30
30
  */
31
31
  export class ChangesetReader {
32
+ static defaultSpillThresholdInBytes = 50 * 1024 * 1024; // 50 MiB
32
33
  _nativeReader = new IModelNative.platform.ChangesetReader();
33
34
  // Internal options — keep ECClassId as raw Id so the unifier can use it as-is.
34
35
  _rowOptions;
@@ -43,6 +44,7 @@ export class ChangesetReader {
43
44
  /**
44
45
  * `true` when the current row belongs to an EC-mapped table.
45
46
  * Valid only after a successful call to [[step]].
47
+ * @throws [[IModelError]] if called before a successful [[step]] call.
46
48
  * @beta
47
49
  */
48
50
  get isECTable() {
@@ -53,6 +55,7 @@ export class ChangesetReader {
53
55
  /**
54
56
  * Name of the SQLite table for the current change row.
55
57
  * Valid only after a successful call to [[step]].
58
+ * @throws [[IModelError]] if called before a successful [[step]] call.
56
59
  * @beta
57
60
  */
58
61
  get tableName() {
@@ -63,6 +66,7 @@ export class ChangesetReader {
63
66
  /**
64
67
  * `true` when the current change was applied indirectly
65
68
  * Valid only after a successful call to [[step]].
69
+ * @throws [[IModelError]] if called before a successful [[step]] call.
66
70
  * @beta
67
71
  */
68
72
  get isIndirectChange() {
@@ -105,6 +109,7 @@ export class ChangesetReader {
105
109
  * @param args.invert When `true`, invert all operations (Insert↔Delete).
106
110
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
107
111
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
112
+ * @throws if the native layer fails to open the file.
108
113
  * @beta
109
114
  */
110
115
  static openFile(args) {
@@ -116,7 +121,7 @@ export class ChangesetReader {
116
121
  reader._nativeReader.openFile(args.db[_nativeDb], args.fileName, args.invert ?? false, reader._propFilter);
117
122
  }
118
123
  catch (e) {
119
- reader.close();
124
+ reader.handleCloseErrorWhileOpening(e);
120
125
  throw e;
121
126
  }
122
127
  return reader;
@@ -127,20 +132,26 @@ export class ChangesetReader {
127
132
  * @param args.db Database with schema at or ahead of the last changeset.
128
133
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
129
134
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
135
+ * @param args.spillThresholdInBytes When the total size of the changeset data in the change group exceeds this threshold (in bytes),
136
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
137
+ * This keeps peak memory usage bounded, making the API suitable for processing large changeset groups under low-memory conditions.
138
+ * Defaults to 50 MiB.
139
+ * @throws if `changesetFiles` is empty, or if the native layer fails to open
140
+ * the group.
130
141
  * @beta
131
142
  */
132
143
  static openGroup(args) {
133
144
  if (args.changesetFiles.length === 0)
134
- throw new Error("changesetFiles must contain at least one file.");
145
+ throw new IModelError(IModelStatus.BadArg, "changesetFiles must contain at least one file.");
135
146
  const reader = new ChangesetReader(args.db);
136
147
  reader._rowOptions = args.rowOptions;
137
148
  const propFilter = args.propFilter ?? PropertyFilter.All;
138
149
  reader._propFilter = propFilter;
139
150
  try {
140
- reader._nativeReader.openGroup(args.db[_nativeDb], args.changesetFiles, args.invert ?? false, reader._propFilter);
151
+ reader._nativeReader.openGroup(args.db[_nativeDb], args.changesetFiles, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);
141
152
  }
142
153
  catch (e) {
143
- reader.close();
154
+ reader.handleCloseErrorWhileOpening(e);
144
155
  throw e;
145
156
  }
146
157
  return reader;
@@ -151,6 +162,12 @@ export class ChangesetReader {
151
162
  * @param args.includeInMemoryChanges Also include in-memory (not yet saved to disk) changes.
152
163
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
153
164
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
165
+ * @param args.spillThresholdInBytes When the total size of all local un-pushed saved changes exceeds this threshold (in bytes),
166
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
167
+ * This keeps peak memory usage bounded, making the API suitable for iModels with large local change backlogs under low-memory conditions.
168
+ * Defaults to 50 MiB.
169
+ * @throws if the native layer
170
+ * fails to open the local changes.
154
171
  * @beta
155
172
  */
156
173
  static openLocalChanges(args) {
@@ -159,10 +176,10 @@ export class ChangesetReader {
159
176
  const propFilter = args.propFilter ?? PropertyFilter.All;
160
177
  reader._propFilter = propFilter;
161
178
  try {
162
- reader._nativeReader.openLocalChanges(args.db[_nativeDb], args.includeInMemoryChanges ?? false, args.invert ?? false, reader._propFilter);
179
+ reader._nativeReader.openLocalChanges(args.db[_nativeDb], args.includeInMemoryChanges ?? false, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);
163
180
  }
164
181
  catch (e) {
165
- reader.close();
182
+ reader.handleCloseErrorWhileOpening(e);
166
183
  throw e;
167
184
  }
168
185
  return reader;
@@ -172,6 +189,11 @@ export class ChangesetReader {
172
189
  * @param args.db Must be an [IModelDb]($backend).
173
190
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
174
191
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
192
+ * @param args.spillThresholdInBytes When the total size of the in-memory (unsaved) change data exceeds this threshold (in bytes),
193
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
194
+ * This keeps peak memory usage bounded, making the API suitable for large in-memory transactions under low-memory conditions.
195
+ * Defaults to 50 MiB.
196
+ * @throws if the native layer encounters an error while opening the in-memory changes.
175
197
  * @beta
176
198
  */
177
199
  static openInMemoryChanges(args) {
@@ -180,10 +202,10 @@ export class ChangesetReader {
180
202
  const propFilter = args.propFilter ?? PropertyFilter.All;
181
203
  reader._propFilter = propFilter;
182
204
  try {
183
- reader._nativeReader.openInMemoryChanges(args.db[_nativeDb], args.invert ?? false, reader._propFilter);
205
+ reader._nativeReader.openInMemoryChanges(args.db[_nativeDb], args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);
184
206
  }
185
207
  catch (e) {
186
- reader.close();
208
+ reader.handleCloseErrorWhileOpening(e);
187
209
  throw e;
188
210
  }
189
211
  return reader;
@@ -194,22 +216,40 @@ export class ChangesetReader {
194
216
  * @param args.txnId The id of the saved transaction to read.
195
217
  * @param args.valueOptions Row adaptor options controlling how EC property values are formatted.
196
218
  * @param args.propFilter Controls which properties are included. Defaults to `All`.
219
+ * @param args.spillThresholdInBytes When the total size of the transaction's change data exceeds this threshold (in bytes),
220
+ * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.
221
+ * This keeps peak memory usage bounded, making the API suitable for large transactions under low-memory conditions.
222
+ * Defaults to 50 MiB.
223
+ * @throws if `txnId` is not found, or
224
+ * the native layer fails to open the transaction data.
197
225
  * @beta
198
226
  */
199
227
  static openTxn(args) {
200
228
  const reader = new ChangesetReader(args.db);
201
- reader._rowOptions = args.rowOptions ?? {};
229
+ reader._rowOptions = args.rowOptions;
202
230
  const propFilter = args.propFilter ?? PropertyFilter.All;
203
231
  reader._propFilter = propFilter;
204
232
  try {
205
- reader._nativeReader.openTxn(args.db[_nativeDb], args.txnId, args.invert ?? false, reader._propFilter);
233
+ reader._nativeReader.openTxn(args.db[_nativeDb], args.txnId, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);
206
234
  }
207
235
  catch (e) {
208
- reader.close();
236
+ reader.handleCloseErrorWhileOpening(e);
209
237
  throw e;
210
238
  }
211
239
  return reader;
212
240
  }
241
+ /** Handle errors that occur while auto closing the reader if there is also an error while opening the reader */
242
+ handleCloseErrorWhileOpening(e) {
243
+ try {
244
+ this.close();
245
+ }
246
+ catch (closeError) {
247
+ throw new IModelError(IModelStatus.BadArg, `Failed to open ChangesetReader with error ${e instanceof Error ? e.message : String(e)}.
248
+ Additionally, that triggered an automatic closure of the reader
249
+ releasing native resources which also failed with failure ${closeError instanceof Error ? closeError.message : String(closeError)}.
250
+ Check native error logs for more details.`);
251
+ }
252
+ }
213
253
  // ---------------------------------------------------------------------------
214
254
  // Filtering
215
255
  // ---------------------------------------------------------------------------
@@ -218,6 +258,7 @@ export class ChangesetReader {
218
258
  * That means the rows for changes from other tables will be skipped entirely and won't be visible through the reader.
219
259
  * @param tableNames SQLite table names to include.
220
260
  * Note: Table names must be provided in the correct case for proper filtering.
261
+ * @throws if the native layer encounters an error while setting the filter.
221
262
  * @beta
222
263
  */
223
264
  setTableNameFilters(tableNames) {
@@ -227,6 +268,7 @@ export class ChangesetReader {
227
268
  * Restrict iteration to changes with the given operation types.
228
269
  * That means the rows for changes with other operation types will be skipped entirely and won't be visible through the reader.
229
270
  * @param ops Operations to include.
271
+ * @throws if the native layer encounters an error while setting the filter.
230
272
  * @beta
231
273
  */
232
274
  setOpCodeFilters(ops) {
@@ -237,6 +279,7 @@ export class ChangesetReader {
237
279
  * That means the rows for changes from other EC classes will be skipped entirely and won't be visible through the reader.
238
280
  * @param classNames EC class names to include. The classNames should be in the full name format(i.e. "SchemaName:ClassName").
239
281
  * Note: Schema names and class names must be provided in the correct case for proper filtering. Derived classes are not automatically included, so they must be specified explicitly if needed.
282
+ * @throws if the native layer encounters an error while setting the filter.
240
283
  * @beta
241
284
  */
242
285
  setClassNameFilters(classNames) {
@@ -244,6 +287,7 @@ export class ChangesetReader {
244
287
  }
245
288
  /**
246
289
  * Remove the table-name filters
290
+ * @throws if the native layer encounters an error.
247
291
  * @beta
248
292
  */
249
293
  clearTableNameFilters() {
@@ -251,6 +295,7 @@ export class ChangesetReader {
251
295
  }
252
296
  /**
253
297
  * Remove the op-code filters
298
+ * @throws if the native layer encounters an error.
254
299
  * @beta
255
300
  */
256
301
  clearOpCodeFilters() {
@@ -258,17 +303,61 @@ export class ChangesetReader {
258
303
  }
259
304
  /**
260
305
  * Remove the class-name filters
306
+ * @throws if the native layer encounters an error.
261
307
  * @beta
262
308
  */
263
309
  clearClassNameFilters() {
264
310
  this._nativeReader.clearClassNameFilters();
265
311
  }
266
312
  // ---------------------------------------------------------------------------
313
+ // Strict mode
314
+ // ---------------------------------------------------------------------------
315
+ /**
316
+ * Enable strict mode on the reader.
317
+ *
318
+ * Strict mode affects how the reader handles a **column-count mismatch** between a change
319
+ * record and the corresponding live database table. Such a mismatch can occur when columns
320
+ * have been added to a table after the changeset was created.
321
+ *
322
+ * When strict mode is **enabled**: if the number of columns recorded in a change row differs
323
+ * from the number of columns currently present in the live table, the reader throws an error
324
+ * instead of processing that row.
325
+ *
326
+ * Use strict mode when you need to be certain that every change row is interpreted against
327
+ * exactly the schema that was in effect when the changeset was written.
328
+ *
329
+ * @see [[disableStrictMode]] — the default (lenient) behaviour.
330
+ * @throws if the native layer encounters an error.
331
+ * @beta
332
+ */
333
+ enableStrictMode() {
334
+ this._nativeReader.enableStrictMode();
335
+ }
336
+ /**
337
+ * Disable strict mode on the reader (this is the default).
338
+ *
339
+ * When strict mode is **disabled**: if the number of columns recorded in a change row differs
340
+ * from the number of columns currently present in the live table, the reader takes the
341
+ * **minimum** of the two column counts and proceeds normally with that subset. This is safe
342
+ * because SQLite only ever appends new columns at the end of a table and never removes them —
343
+ * so older change records simply lack the trailing columns that were added later, and those
344
+ * missing columns are silently ignored.
345
+ *
346
+ * @see [[enableStrictMode]] — throw on column-count mismatches instead.
347
+ * @throws if the native layer encounters an error.
348
+ * @beta
349
+ */
350
+ disableStrictMode() {
351
+ this._nativeReader.disableStrictMode();
352
+ }
353
+ // ---------------------------------------------------------------------------
267
354
  // Iteration
268
355
  // ---------------------------------------------------------------------------
269
356
  /**
270
357
  * Advance to the next change and populate `inserted` and/or `deleted`.
271
358
  * @returns `true` while positioned on a valid change; `false` when the stream is exhausted.
359
+ * @throws if the native layer encounters an error while reading or decoding
360
+ * the next change.
272
361
  * @beta
273
362
  */
274
363
  step() {
@@ -333,6 +422,7 @@ export class ChangesetReader {
333
422
  /**
334
423
  * SQLite opcode of the current change.
335
424
  * Valid only after a successful call to [[step]].
425
+ * @throws [[IModelError]] if called before a successful [[step]] call.
336
426
  * @beta
337
427
  */
338
428
  get op() {
@@ -345,6 +435,10 @@ export class ChangesetReader {
345
435
  // ---------------------------------------------------------------------------
346
436
  /**
347
437
  * Close the reader and release all native resources.
438
+ *
439
+ * @throws if the native layer encounters an error during cleanup. Native resources
440
+ * are not fully released when this throws — check the native error
441
+ * logs for details.
348
442
  * @beta
349
443
  */
350
444
  close() {
@@ -358,7 +452,9 @@ export class ChangesetReader {
358
452
  this._nativeReader.close();
359
453
  }
360
454
  /**
361
- * Implements the `Disposable` contract — calls [[close]].
455
+ * Implements the `Disposable` contract — delegates to [[close]].
456
+ *
457
+ * @throws if the native layer fails to release its resources (re-thrown from [[close]]).
362
458
  * @beta
363
459
  */
364
460
  [Symbol.dispose]() {