tsondb 0.23.2 → 0.23.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.
@@ -7,6 +7,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  }
8
8
  return path;
9
9
  };
10
+ import { isNotNullish } from "@elyukai/utils/nullable";
10
11
  import { omitUndefinedKeys } from "@elyukai/utils/object";
11
12
  import { assertExhaustive } from "@elyukai/utils/typeSafety";
12
13
  import Debug from "debug";
@@ -75,15 +76,38 @@ const passedArguments = parseArguments({
75
76
  },
76
77
  },
77
78
  },
79
+ compress: {
80
+ name: "compress",
81
+ options: {
82
+ path: {
83
+ name: "path",
84
+ alias: "p",
85
+ type: String,
86
+ },
87
+ indentation: {
88
+ name: "indentation",
89
+ alias: "i",
90
+ type: Number,
91
+ },
92
+ },
93
+ },
94
+ },
95
+ options: {
96
+ config: {
97
+ name: "config",
98
+ alias: "c",
99
+ type: String,
100
+ },
78
101
  },
79
102
  });
80
103
  // import the config
81
104
  const possibleConfigNames = [
105
+ passedArguments.options?.config,
82
106
  "tsondb.config.mts",
83
107
  "tsondb.config.ts",
84
108
  "tsondb.config.mjs",
85
109
  "tsondb.config.js",
86
- ];
110
+ ].filter(isNotNullish);
87
111
  const config = await (async () => {
88
112
  for (const configName of possibleConfigNames) {
89
113
  const fullPath = join(cwd(), configName);
@@ -204,6 +228,16 @@ else {
204
228
  }
205
229
  break;
206
230
  }
231
+ case "compress": {
232
+ debug(`running command: compress`);
233
+ const { path, indentation } = passedArguments.command.options ?? {};
234
+ if (path === undefined) {
235
+ throw new Error("No path specified for compress command.");
236
+ }
237
+ const db = await createDB(config, config.validationOptions, true);
238
+ await db.compressToSingleFile(join(cwd(), path), indentation);
239
+ break;
240
+ }
207
241
  default:
208
242
  assertExhaustive(commandName);
209
243
  }
@@ -41,7 +41,7 @@ export class TSONDB extends ReadonlyTSONDB {
41
41
  #locked = false;
42
42
  #hooks = {};
43
43
  constructor(options) {
44
- super(options);
44
+ super({ ...options, allowCompressedFile: false });
45
45
  this.#git = options.git;
46
46
  this.#gitWrapper = Lazy.of(() => this.#git
47
47
  ? new Git(this, this.#git.client, this.#git.root, this.dataRootPath, () => this._data, (data) => {
@@ -1,6 +1,6 @@
1
1
  import type { InstanceContainer, InstanceContainerOverview, SingletonInstanceContainer } from "../shared/utils/instances.ts";
2
2
  import type { FormatterOptions } from "./config.ts";
3
- import { type ChildEntity, type ChildEntityConfig, type ChildEntityName, type DefaultTSONDBTypes, type Entity, type EntityName, type SingletonEntityName, type TSONDBOptions, type ValidationOptions } from "./index.ts";
3
+ import type { ChildEntity, ChildEntityConfig, ChildEntityName, DefaultTSONDBTypes, Entity, EntityName, SingletonEntityName, TSONDBOptions, ValidationOptions } from "./index.ts";
4
4
  import type { Output } from "./output.ts";
5
5
  import type { EntityDecl } from "./schema/dsl/index.ts";
6
6
  import type { IdArgsVariant } from "./schema/generatedTypeHelpers.ts";
@@ -24,6 +24,7 @@ export declare class ReadonlyTSONDB<T extends DefaultTSONDBTypes = DefaultTSONDB
24
24
  referencesToInstances: ReferencesToInstances;
25
25
  validationOptions: ValidationOptions;
26
26
  formatterOptions?: Partial<FormatterOptions> | undefined;
27
+ allowCompressedFile: boolean;
27
28
  });
28
29
  /**
29
30
  * Creates a new TSONDB instance with the specified options.
@@ -3,10 +3,9 @@ import { compareNumber, reduceCompare } from "@elyukai/utils/ordering";
3
3
  import Debug from "debug";
4
4
  import { stderr } from "node:process";
5
5
  import { styleText } from "node:util";
6
- import { TSONDB, } from "./index.js";
7
6
  import { getDisplayName, getDisplayNameWithId } from "./schema/detached.js";
8
7
  import { isEntityDeclWithParentReference } from "./schema/guards.js";
9
- import { checkLocales, generateOutputs, initData, prepareFolders, validate } from "./shared.js";
8
+ import { checkLocales, generateOutputs, initData, validate } from "./shared.js";
10
9
  import { DatabaseInMemory } from "./utils/databaseInMemory.js";
11
10
  import { getAllInstanceOverviewsByEntityName, getDisplayNameFromEntityInstance, getInstanceOverview, getInstanceOverviewsByEntityName, } from "./utils/displayName.js";
12
11
  import { formatInstance, readInstance, readSingletonInstance } from "./utils/files.js";
@@ -20,6 +19,7 @@ export class ReadonlyTSONDB {
20
19
  #dataRootPath;
21
20
  #schema;
22
21
  #locales;
22
+ #allowCompressedFile;
23
23
  _referencesToInstances;
24
24
  _validationOptions;
25
25
  _formatterOptions;
@@ -31,6 +31,7 @@ export class ReadonlyTSONDB {
31
31
  this._referencesToInstances = options.referencesToInstances;
32
32
  this._validationOptions = options.validationOptions;
33
33
  this._formatterOptions = options.formatterOptions;
34
+ this.#allowCompressedFile = options.allowCompressedFile;
34
35
  }
35
36
  /**
36
37
  * Creates a new TSONDB instance with the specified options.
@@ -39,10 +40,7 @@ export class ReadonlyTSONDB {
39
40
  * @param skipReferenceCache If set to `true`, the reference cache will not be created during initialization. This can speed up the initialization process, but referential integrity checks will not work correctly until the cache is created. This should only be set to `true` if you plan to call `sync()` immediately after initialization.
40
41
  */
41
42
  static async create(options, skipReferenceCache = false) {
42
- const { entities } = options.schema;
43
43
  debug("using data root path: %s", options.dataRootPath);
44
- await prepareFolders(options.schema.version, options.dataRootPath, entities);
45
- debug("prepared folders");
46
44
  const { localeEntity } = options.schema;
47
45
  if (!localeEntity && options.locales) {
48
46
  throw new Error("Schema does not contain a locale entity, locales cannot be provided.");
@@ -57,6 +55,7 @@ export class ReadonlyTSONDB {
57
55
  checkOnlyEntities: [],
58
56
  ...options.validationOptions,
59
57
  },
58
+ allowCompressedFile: true,
60
59
  });
61
60
  return db;
62
61
  }
@@ -135,7 +134,7 @@ export class ReadonlyTSONDB {
135
134
  */
136
135
  async sync() {
137
136
  debug("Syncing with disk ...");
138
- const { data, referencesToInstances } = await initData(this.#dataRootPath, this.#schema, this.#locales, undefined, undefined, false, !(this instanceof TSONDB));
137
+ const { data, referencesToInstances } = await initData(this.#dataRootPath, this.#schema, this.#locales, undefined, undefined, false, this.#allowCompressedFile);
139
138
  this._data = data;
140
139
  this._referencesToInstances = referencesToInstances;
141
140
  debug("Synced with disk");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",