tsondb 0.11.3 → 0.11.4

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.
@@ -13,6 +13,7 @@ import { join } from "node:path";
13
13
  import { cwd } from "node:process";
14
14
  import { pathToFileURL } from "node:url";
15
15
  import { parseArguments } from "simple-cli-args";
16
+ import { validateConfigForFormatting, validateConfigForGeneration, validateConfigForServer, validateConfigForTesting, } from "../node/config.js";
16
17
  import { format, generateOutputs, serve, validate } from "../node/index.js";
17
18
  const debug = Debug("tsondb:cli");
18
19
  const passedArguments = parseArguments({
@@ -80,14 +81,17 @@ if (passedArguments.command === undefined) {
80
81
  switch (passedArguments.command.name) {
81
82
  case "generate":
82
83
  debug(`running command: generate`);
84
+ validateConfigForGeneration(config);
83
85
  await generateOutputs(config.schema, config.outputs);
84
86
  break;
85
87
  case "serve":
86
88
  debug(`running command: serve`);
89
+ validateConfigForServer(config);
87
90
  await serve(config.schema, config.dataRootPath, config.defaultLocales, config.homeLayoutSections, config.serverOptions, config.customStylesheetPath);
88
91
  break;
89
92
  case "validate":
90
93
  debug(`running command: validate`);
94
+ validateConfigForTesting(config);
91
95
  if (passedArguments.command.options?.checkReferentialIntegrity !== undefined) {
92
96
  debug(`check referential integrity: ${passedArguments.command.options.checkReferentialIntegrity ? "yes" : "no"}`);
93
97
  }
@@ -102,6 +106,7 @@ switch (passedArguments.command.name) {
102
106
  break;
103
107
  case "format":
104
108
  debug(`running command: format`);
109
+ validateConfigForFormatting(config);
105
110
  await format(config.schema, config.dataRootPath);
106
111
  break;
107
112
  }
@@ -1,12 +1,15 @@
1
1
  import type { Output } from "../shared/output.ts";
2
2
  import type { EntityDecl } from "./schema/index.ts";
3
3
  import type { Schema } from "./schema/Schema.ts";
4
+ /**
5
+ * The main configuration type for TSONDB.
6
+ */
4
7
  export type Config = {
5
8
  serverOptions?: ServerOptions;
6
9
  schema: Schema;
7
- outputs: Output[];
8
- defaultLocales: string[];
9
- dataRootPath: string;
10
+ outputs?: Output[];
11
+ defaultLocales?: string[];
12
+ dataRootPath?: string;
10
13
  homeLayoutSections?: HomeLayoutSection[];
11
14
  customStylesheetPath?: string;
12
15
  };
@@ -18,4 +21,30 @@ export type HomeLayoutSection = {
18
21
  comment?: string;
19
22
  entities: EntityDecl[];
20
23
  };
21
- export declare const validateConfig: (config: Config) => void;
24
+ /**
25
+ * The configuration type required for generation commands.
26
+ */
27
+ export type GenerationConfig = {
28
+ schema: Schema;
29
+ outputs: Output[];
30
+ };
31
+ export declare const validateConfigForGeneration: (config: Config) => asserts config is GenerationConfig;
32
+ /**
33
+ * The configuration type required for any commands that need to read data stored in the database.
34
+ */
35
+ export type DataConfig = {
36
+ schema: Schema;
37
+ dataRootPath: string;
38
+ };
39
+ /**
40
+ * The configuration type required for running the server for the editor.
41
+ */
42
+ export type ServerConfig = DataConfig & {
43
+ serverOptions?: ServerOptions;
44
+ defaultLocales: string[];
45
+ homeLayoutSections?: HomeLayoutSection[];
46
+ customStylesheetPath?: string;
47
+ };
48
+ export declare const validateConfigForServer: (config: Config) => asserts config is ServerConfig;
49
+ export declare const validateConfigForTesting: (config: Config) => asserts config is DataConfig;
50
+ export declare const validateConfigForFormatting: (config: Config) => asserts config is DataConfig;
@@ -1,5 +1,23 @@
1
- export const validateConfig = (config) => {
2
- if (config.defaultLocales.length === 0) {
1
+ export const validateConfigForGeneration = config => {
2
+ if ((config.outputs?.length ?? 0) === 0) {
3
+ throw new Error("At least one output must be specified in the config.");
4
+ }
5
+ };
6
+ export const validateConfigForServer = config => {
7
+ if ((config.defaultLocales?.length ?? 0) === 0) {
3
8
  throw new Error("At least one default locale must be specified in the config.");
4
9
  }
10
+ if (config.dataRootPath === undefined) {
11
+ throw new Error("A data root path must be specified in the config.");
12
+ }
13
+ };
14
+ export const validateConfigForTesting = config => {
15
+ if (config.dataRootPath === undefined) {
16
+ throw new Error("A data root path must be specified in the config.");
17
+ }
18
+ };
19
+ export const validateConfigForFormatting = config => {
20
+ if (config.dataRootPath === undefined) {
21
+ throw new Error("A data root path must be specified in the config.");
22
+ }
5
23
  };
@@ -228,6 +228,7 @@ gitApi.post("/pull", async (req, res) => {
228
228
  const status = await req.git.status();
229
229
  const remotes = await req.git.getRemotes();
230
230
  await req.git.pull(remotes[0]?.name, status.current ?? undefined);
231
+ await reinit(req);
231
232
  res.set("Content-Type", "text/plain");
232
233
  res.status(200).send("Pull successful");
233
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.11.3",
3
+ "version": "0.11.4",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",