inibase 1.6.3 → 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
@@ -633,6 +633,16 @@ const db = new Inibase("/databaseName");
633
633
  const users = await db.get("user", undefined, {
634
634
  columns: ["!username", "!address.street"],
635
635
  });
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
+
642
+ // Get all columns explicitly with the "*" wildcard
643
+ const all = await db.get("user", undefined, {
644
+ columns: ["*"],
645
+ });
636
646
  ```
637
647
 
638
648
  </blockquote>
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,8 +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
- this.validateName(column);
1134
+ this.validateColumns(options.columns);
1114
1135
  if (options.columns.length && !options.columns.includes("id"))
1115
1136
  options.columns.push("id");
1116
1137
  }
@@ -1355,10 +1376,9 @@ export default class Inibase {
1355
1376
  };
1356
1377
  this.validateName(tableName);
1357
1378
  if (options.columns)
1358
- for (const column of (Array.isArray(options.columns)
1379
+ this.validateColumns((Array.isArray(options.columns)
1359
1380
  ? options.columns
1360
- : [options.columns]))
1361
- this.validateName(column);
1381
+ : [options.columns]));
1362
1382
  const tablePath = join(this.databasePath, tableName);
1363
1383
  await this.getTable(tableName);
1364
1384
  if (!globalConfig[this.databasePath].tables?.get(tableName)?.schema)
@@ -1441,10 +1461,9 @@ export default class Inibase {
1441
1461
  const renameList = [];
1442
1462
  this.validateName(tableName);
1443
1463
  if (options.columns)
1444
- for (const column of (Array.isArray(options.columns)
1464
+ this.validateColumns((Array.isArray(options.columns)
1445
1465
  ? options.columns
1446
- : [options.columns]))
1447
- this.validateName(column);
1466
+ : [options.columns]));
1448
1467
  const tablePath = join(this.databasePath, tableName);
1449
1468
  await this.throwErrorIfTableEmpty(tableName);
1450
1469
  let clonedData = structuredClone(data);
package/dist/utils.js CHANGED
@@ -740,7 +740,6 @@ export const createError = (language, name, variable) => {
740
740
  export const isValidName = (input) => typeof input === "string" &&
741
741
  input.length > 0 &&
742
742
  input.length <= 255 &&
743
- input !== "*" &&
744
743
  validNamePattern.test(input);
745
744
  // Word characters: Latin alphanumerics, underscores, hyphens and Arabic blocks.
746
745
  const nameWordCharClass = "a-zA-Z0-9_\\u0600-\\u06FF\\u0750-\\u077F\\u08A0-\\u08FF-";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",