inibase 1.6.4 → 1.6.5

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/README.md CHANGED
@@ -634,6 +634,11 @@ const users = await db.get("user", undefined, {
634
634
  columns: ["!username", "!address.street"],
635
635
  });
636
636
 
637
+ // Columns accept dotted nested paths (e.g. "address.street" => nested field)
638
+ const nested = await db.get("user", undefined, {
639
+ columns: ["address.street", "hobbies.name"],
640
+ });
641
+
637
642
  // Get all columns explicitly with the "*" wildcard
638
643
  const all = await db.get("user", undefined, {
639
644
  columns: ["*"],
package/dist/index.d.ts CHANGED
@@ -79,6 +79,16 @@ export default class Inibase {
79
79
  constructor(database: string, mainFolder?: string, language?: ErrorLang);
80
80
  createError(name: ErrorCode, variable?: string | number | (string | number)[]): Error;
81
81
  private validateName;
82
+ /**
83
+ * Validates column paths used in the `columns` option.
84
+ *
85
+ * Each column may be a nested path of dot-separated names
86
+ * (e.g. "address.street", "hobbies.name") and may optionally
87
+ * start with "!" for exclusion. The "*" wildcard (select all)
88
+ * and its "!*" counterpart are special values and are skipped.
89
+ * Every segment of a path is validated individually.
90
+ */
91
+ private validateColumns;
82
92
  private validateSchema;
83
93
  private getFileExtension;
84
94
  private schemaToIdsPath;
package/dist/index.js CHANGED
@@ -64,6 +64,28 @@ export default class Inibase {
64
64
  validateName(name) {
65
65
  Utils.validateName(name, this.language);
66
66
  }
67
+ /**
68
+ * Validates column paths used in the `columns` option.
69
+ *
70
+ * Each column may be a nested path of dot-separated names
71
+ * (e.g. "address.street", "hobbies.name") and may optionally
72
+ * start with "!" for exclusion. The "*" wildcard (select all)
73
+ * and its "!*" counterpart are special values and are skipped.
74
+ * Every segment of a path is validated individually.
75
+ */
76
+ validateColumns(columns) {
77
+ for (const column of columns) {
78
+ if (column === "*" || column === "!*")
79
+ continue;
80
+ const path = column.startsWith("!") ? column.slice(1) : column;
81
+ for (const segment of path.split(".")) {
82
+ if (!segment)
83
+ this.validateName(column);
84
+ else
85
+ this.validateName(segment);
86
+ }
87
+ }
88
+ }
67
89
  validateSchema(schema) {
68
90
  Utils.validateSchema(schema, this.language);
69
91
  }
@@ -1109,9 +1131,7 @@ export default class Inibase {
1109
1131
  options.columns = Array.isArray(options.columns)
1110
1132
  ? options.columns
1111
1133
  : [options.columns];
1112
- for (const column of options.columns)
1113
- if (column !== "*")
1114
- this.validateName(column);
1134
+ this.validateColumns(options.columns);
1115
1135
  if (options.columns.length && !options.columns.includes("id"))
1116
1136
  options.columns.push("id");
1117
1137
  }
@@ -1356,11 +1376,9 @@ export default class Inibase {
1356
1376
  };
1357
1377
  this.validateName(tableName);
1358
1378
  if (options.columns)
1359
- for (const column of (Array.isArray(options.columns)
1379
+ this.validateColumns((Array.isArray(options.columns)
1360
1380
  ? options.columns
1361
- : [options.columns]))
1362
- if (column !== "*")
1363
- this.validateName(column);
1381
+ : [options.columns]));
1364
1382
  const tablePath = join(this.databasePath, tableName);
1365
1383
  await this.getTable(tableName);
1366
1384
  if (!globalConfig[this.databasePath].tables?.get(tableName)?.schema)
@@ -1443,11 +1461,9 @@ export default class Inibase {
1443
1461
  const renameList = [];
1444
1462
  this.validateName(tableName);
1445
1463
  if (options.columns)
1446
- for (const column of (Array.isArray(options.columns)
1464
+ this.validateColumns((Array.isArray(options.columns)
1447
1465
  ? options.columns
1448
- : [options.columns]))
1449
- if (column !== "*")
1450
- this.validateName(column);
1466
+ : [options.columns]));
1451
1467
  const tablePath = join(this.databasePath, tableName);
1452
1468
  await this.throwErrorIfTableEmpty(tableName);
1453
1469
  let clonedData = structuredClone(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",