tsondb 0.19.8 → 0.19.10
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.d.ts
CHANGED
|
@@ -193,6 +193,12 @@ export declare class TSONDB<T extends DefaultTSONDBTypes = DefaultTSONDBTypes> {
|
|
|
193
193
|
* The configured locales for this TSONDB instance.
|
|
194
194
|
*/
|
|
195
195
|
get locales(): string[];
|
|
196
|
+
/**
|
|
197
|
+
* Sets the locales for this TSONDB instance.
|
|
198
|
+
*
|
|
199
|
+
* The provided locales must exist in the database if a locale entity is defined in the schema.
|
|
200
|
+
*/
|
|
201
|
+
setLocales(locales: string[]): void;
|
|
196
202
|
/**
|
|
197
203
|
* The loaded schema for this TSONDB instance.
|
|
198
204
|
*/
|
package/dist/src/node/index.js
CHANGED
|
@@ -55,15 +55,18 @@ const getGit = async (dataRootPath) => {
|
|
|
55
55
|
return { git };
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
-
const
|
|
59
|
-
debug("loading database into memory ...");
|
|
60
|
-
let data = await DatabaseInMemory.load(dataRootPath, schema.entities);
|
|
61
|
-
debug("done");
|
|
58
|
+
const checkLocales = (schema, data, locales) => {
|
|
62
59
|
const localeEntity = schema.localeEntity;
|
|
63
60
|
if (localeEntity &&
|
|
64
61
|
!locales.every(locale => data.hasInstanceOfEntityById(localeEntity.name, locale))) {
|
|
65
62
|
throw new Error("All provided locales must exist in the database.");
|
|
66
63
|
}
|
|
64
|
+
};
|
|
65
|
+
const initData = async (dataRootPath, schema, locales, git, gitStatus, skipReferenceCache) => {
|
|
66
|
+
debug("loading database into memory ...");
|
|
67
|
+
let data = await DatabaseInMemory.load(dataRootPath, schema.entities);
|
|
68
|
+
debug("done");
|
|
69
|
+
checkLocales(schema, data, locales);
|
|
67
70
|
const serializedDeclarationsByName = Object.fromEntries(schema.resolvedDeclarations.map(decl => [decl.name, serializeNode(decl)]));
|
|
68
71
|
let referencesToInstances;
|
|
69
72
|
if (!skipReferenceCache) {
|
|
@@ -327,17 +330,24 @@ export class TSONDB {
|
|
|
327
330
|
debug("Transaction validation failed with %d error%s", errors.length, errors.length === 1 ? "" : "s");
|
|
328
331
|
throw new AggregateError(errors, "Validation errors occurred");
|
|
329
332
|
}
|
|
333
|
+
debug("Applying changes to disk ...");
|
|
330
334
|
const diskResult = await applyStepsToDisk(this.#dataRootPath, steps);
|
|
331
335
|
if (isError(diskResult)) {
|
|
332
336
|
debug("Error applying changes to disk: %s", diskResult.error.message);
|
|
333
337
|
throw diskResult.error;
|
|
334
338
|
}
|
|
339
|
+
else {
|
|
340
|
+
debug("Changes applied to disk successfully");
|
|
341
|
+
}
|
|
335
342
|
if (this.#git) {
|
|
343
|
+
debug("Updating git status ...");
|
|
336
344
|
const status = await this.#git.client.status();
|
|
337
345
|
const newDbWithUpdatedGit = attachGitStatusToDatabaseInMemory(newData, this.#dataRootPath, this.#git.root, status);
|
|
346
|
+
debug("Git status updated");
|
|
338
347
|
this.#data = newDbWithUpdatedGit;
|
|
339
348
|
}
|
|
340
349
|
else {
|
|
350
|
+
debug("No git repository, skipping git status update");
|
|
341
351
|
this.#data = newData;
|
|
342
352
|
}
|
|
343
353
|
this.#referencesToInstances = newRefs;
|
|
@@ -468,6 +478,15 @@ export class TSONDB {
|
|
|
468
478
|
get locales() {
|
|
469
479
|
return this.#locales;
|
|
470
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* Sets the locales for this TSONDB instance.
|
|
483
|
+
*
|
|
484
|
+
* The provided locales must exist in the database if a locale entity is defined in the schema.
|
|
485
|
+
*/
|
|
486
|
+
setLocales(locales) {
|
|
487
|
+
checkLocales(this.#schema, this.#data, locales);
|
|
488
|
+
this.#locales = locales;
|
|
489
|
+
}
|
|
471
490
|
/**
|
|
472
491
|
* The loaded schema for this TSONDB instance.
|
|
473
492
|
*/
|
|
@@ -37,7 +37,17 @@ const renderTypeParameters = (options, params) => syntax `${params.length === 0
|
|
|
37
37
|
: syntax `<${combineSyntaxes(params.map(param => param.constraint === undefined
|
|
38
38
|
? param.name
|
|
39
39
|
: syntax `${param.name} extends ${renderType(options, param.constraint)}`), ", ")}>`}`;
|
|
40
|
-
const renderArrayType = (options, type) =>
|
|
40
|
+
const renderArrayType = (options, type) => type.minItems !== undefined && type.minItems === type.maxItems
|
|
41
|
+
? combineSyntaxes([
|
|
42
|
+
"[",
|
|
43
|
+
renderType(options, type.items),
|
|
44
|
+
...Array.from({ length: type.minItems - 1 }, () => [
|
|
45
|
+
", ",
|
|
46
|
+
renderType(options, type.items),
|
|
47
|
+
]).flat(),
|
|
48
|
+
"]",
|
|
49
|
+
])
|
|
50
|
+
: syntax `${renderType(options, type.items)}[]`;
|
|
41
51
|
const wrapAsObject = (options, str) => syntax `{${EOL}${indent(options.indentation, 1, str)}${EOL}}`;
|
|
42
52
|
const renderObjectType = (options, type) => {
|
|
43
53
|
return wrapAsObject(options, combineSyntaxes(Object.entries(type.properties)
|
|
@@ -49,6 +49,7 @@ export const createServer = async (db, homeLayoutSections, options, validationOp
|
|
|
49
49
|
debug("%s %s", req.method, req.originalUrl);
|
|
50
50
|
Object.assign(req, requestLocals);
|
|
51
51
|
req.locales = getLocalesFromRequest(req) ?? req.defaultLocales;
|
|
52
|
+
req.db.setLocales(req.locales);
|
|
52
53
|
next();
|
|
53
54
|
});
|
|
54
55
|
app.use("/api", api);
|