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.
- package/dist/src/node/index.js +36 -30
- package/package.json +1 -1
package/dist/src/node/index.js
CHANGED
|
@@ -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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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 (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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("
|
|
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
|
}
|