tsondb 0.23.0 → 0.23.1

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.
@@ -25,7 +25,7 @@ export type FormatterOptions = {
25
25
  markdown?: Partial<MarkdownFormatterOptions> | false;
26
26
  };
27
27
  export type ServerOptions = {
28
- port: number;
28
+ port?: number;
29
29
  homeLayoutSections?: HomeLayoutSection[];
30
30
  customStylesheetPath?: string;
31
31
  customAssetsPath?: string;
@@ -215,7 +215,9 @@ export declare class TSONDB<T extends DefaultTSONDBTypes = DefaultTSONDBTypes> e
215
215
  * @param indentation Optional. If provided, the JSON output will be formatted with the specified number of spaces for indentation. If not provided, the output will be minified without any extra spaces.
216
216
  */
217
217
  compressToSingleFile(path: string, indentation?: number): Promise<void>;
218
- serve(config: ServerOptions, callback?: (error?: NodeJS.ErrnoException) => void): void;
218
+ serve(config?: (ServerOptions & {
219
+ callback?: (error?: NodeJS.ErrnoException) => void;
220
+ }) | ((error?: NodeJS.ErrnoException) => void)): void;
219
221
  }
220
222
  export type TSONDBWithGit<T extends DefaultTSONDBTypes = DefaultTSONDBTypes> = TSONDB<T> & {
221
223
  git: Git<T>;
@@ -350,7 +350,8 @@ export class TSONDB extends ReadonlyTSONDB {
350
350
  async compressToSingleFile(path, indentation) {
351
351
  await writeFile(path, JSON.stringify(createCompressedDatabaseFile(this._data, this.schema.version), undefined, indentation), "utf-8");
352
352
  }
353
- serve(config, callback) {
354
- createServer(this, { serverOptions: config, validationOptions: this._validationOptions }, callback);
353
+ serve(config) {
354
+ const { callback, ...otherConfig } = typeof config === "function" ? { callback: config } : (config ?? {});
355
+ createServer(this, { serverOptions: otherConfig, validationOptions: this._validationOptions }, callback);
355
356
  }
356
357
  }
@@ -5,9 +5,7 @@ import { dirname, join } from "node:path";
5
5
  import { api } from "./api/index.js";
6
6
  import { getLocalesFromRequest } from "./utils/locales.js";
7
7
  const debug = Debug("tsondb:server");
8
- const defaultOptions = {
9
- port: 3000,
10
- };
8
+ const DEFAULT_PORT = 3000;
11
9
  const staticNodeModule = (moduleName) => {
12
10
  const pathToPackageJson = findPackageJSON(moduleName, import.meta.url);
13
11
  if (!pathToPackageJson) {
@@ -17,10 +15,7 @@ const staticNodeModule = (moduleName) => {
17
15
  };
18
16
  export const createServer = (db, config, callback) => {
19
17
  const { serverOptions: options, validationOptions } = config;
20
- const { port, homeLayoutSections, customAssetsPath, customStylesheetPath } = {
21
- ...defaultOptions,
22
- ...options,
23
- };
18
+ const { port = DEFAULT_PORT, homeLayoutSections, customAssetsPath, customStylesheetPath, } = options ?? {};
24
19
  const app = express();
25
20
  app.use(express.static(join(import.meta.dirname, "../../../../public")));
26
21
  app.use("/js/node_modules/preact", staticNodeModule("preact"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",