tsondb 0.19.2 → 0.19.3

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.
@@ -153,7 +153,7 @@ export class TSONDB {
153
153
  };
154
154
  return validateDeclStructuralIntegrity(validationContext, [], entity, [], instanceContent);
155
155
  }
156
- #validate(data) {
156
+ #validate(data, skipForTransaction = false) {
157
157
  const { checkReferentialIntegrity, checkOnlyEntities } = this.#validationOptions;
158
158
  const entities = this.#schema.entities;
159
159
  const getEntity = this.#schema.getEntity.bind(this.#schema);
@@ -169,40 +169,46 @@ export class TSONDB {
169
169
  validationOptions: this.#validationOptions,
170
170
  useStyling: true,
171
171
  };
172
- debug("Checking structural integrity ...");
173
- const errors = onlyEntities
174
- .flatMap(entity => parallelizeErrors(data
175
- .getAllInstanceContainersOfEntity(entity.name)
176
- .map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${this.#dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateDeclStructuralIntegrity(validationContext, [], entity, [], instance.content)))))
177
- .toSorted((a, b) => a.message.localeCompare(b.message));
178
- if (errors.length > 0) {
179
- const errorCount = countErrors(errors);
180
- debug(`${errorCount.toString()} structural integrity violation${errorCount === 1 ? "" : "s"} found`);
181
- }
182
- else {
183
- debug("No structural integrity violations found");
172
+ const errors = [];
173
+ if (!skipForTransaction) {
174
+ debug("Checking structural integrity ...");
175
+ const structureErrors = onlyEntities
176
+ .flatMap(entity => parallelizeErrors(data
177
+ .getAllInstanceContainersOfEntity(entity.name)
178
+ .map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${this.#dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateDeclStructuralIntegrity(validationContext, [], entity, [], instance.content)))))
179
+ .toSorted((a, b) => a.message.localeCompare(b.message));
180
+ if (structureErrors.length > 0) {
181
+ const errorCount = countErrors(structureErrors);
182
+ debug(`${errorCount.toString()} structural integrity violation${errorCount === 1 ? "" : "s"} found`);
183
+ errors.push(...structureErrors);
184
+ }
185
+ else {
186
+ debug("No structural integrity violations found");
187
+ }
184
188
  }
185
189
  if (errors.length === 0) {
186
- if (checkReferentialIntegrity) {
187
- debug("Checking referential integrity ...");
188
- const referenceValidator = createReferenceValidator(this.#schema.isEntityName.bind(this.#schema), data, true);
189
- const referenceErrors = onlyEntities
190
- .flatMap(entity => parallelizeErrors(data
191
- .getAllInstanceContainersOfEntity(entity.name)
192
- .map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${this.#dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateDeclReferentialIntegrity(validationContext, referenceValidator, [], entity, [], instance.content)))))
193
- .toSorted((a, b) => a.message.localeCompare(b.message));
194
- if (referenceErrors.length > 0) {
195
- const errorCount = countErrors(referenceErrors);
196
- debug(`${errorCount.toString()} referential integrity violation${errorCount === 1 ? "" : "s"} found`);
197
- errors.push(...referenceErrors);
190
+ if (!skipForTransaction) {
191
+ if (checkReferentialIntegrity) {
192
+ debug("Checking referential integrity ...");
193
+ const referenceValidator = createReferenceValidator(this.#schema.isEntityName.bind(this.#schema), data, true);
194
+ const referenceErrors = onlyEntities
195
+ .flatMap(entity => parallelizeErrors(data
196
+ .getAllInstanceContainersOfEntity(entity.name)
197
+ .map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${this.#dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateDeclReferentialIntegrity(validationContext, referenceValidator, [], entity, [], instance.content)))))
198
+ .toSorted((a, b) => a.message.localeCompare(b.message));
199
+ if (referenceErrors.length > 0) {
200
+ const errorCount = countErrors(referenceErrors);
201
+ debug(`${errorCount.toString()} referential integrity violation${errorCount === 1 ? "" : "s"} found`);
202
+ errors.push(...referenceErrors);
203
+ }
204
+ else {
205
+ debug("No referential integrity violations found");
206
+ }
198
207
  }
199
208
  else {
200
- debug("No referential integrity violations found");
209
+ debug("Disabled referential integrity checks, skipping them");
201
210
  }
202
211
  }
203
- else {
204
- debug("Disabled referential integrity checks, skipping them");
205
- }
206
212
  debug("Checking unique constraints ...");
207
213
  const instanceOverviewsByEntityName = getAllInstanceOverviewsByEntityName(getEntity, data, this.#locales);
208
214
  const uniqueConstraintResult = checkUniqueConstraintsForAllEntities(data, onlyEntities, instanceOverviewsByEntityName);
@@ -282,7 +288,7 @@ export class TSONDB {
282
288
  }));
283
289
  const txtResult = txn.getResult();
284
290
  const { data: newData, referencesToInstances: newRefs, steps } = txtResult;
285
- const errors = this.#validate(newData);
291
+ const errors = this.#validate(newData, true);
286
292
  if (errors.length > 0) {
287
293
  throw new AggregateError(errors, "Validation errors occurred");
288
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",