inibase 1.5.5 → 1.5.6
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/dist/cli.js +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -8
- package/dist/utils.js +2 -2
- package/dist/utils.server.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -197,12 +197,12 @@ rl.on("line", async (input) => {
|
|
|
197
197
|
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
198
198
|
break;
|
|
199
199
|
}
|
|
200
|
-
let where
|
|
201
|
-
let page
|
|
202
|
-
let perPage
|
|
203
|
-
let columns
|
|
204
|
-
let sort
|
|
205
|
-
let data
|
|
200
|
+
let where;
|
|
201
|
+
let page;
|
|
202
|
+
let perPage;
|
|
203
|
+
let columns;
|
|
204
|
+
let sort;
|
|
205
|
+
let data;
|
|
206
206
|
if (splitedInput.toSpliced(0, 1).length) {
|
|
207
207
|
const parsedArgs = parseArgs({
|
|
208
208
|
args: splitedInput.toSpliced(0, table ? 1 : 2),
|
package/dist/index.d.ts
CHANGED
|
@@ -151,8 +151,8 @@ export default class Inibase {
|
|
|
151
151
|
get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData) | null>;
|
|
152
152
|
get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData) | null>;
|
|
153
153
|
get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where?: string | number | (string | number)[] | Criteria, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData)[] | null>;
|
|
154
|
-
get<
|
|
155
|
-
get<
|
|
154
|
+
get<_TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number[] | null>;
|
|
155
|
+
get<_TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number | null>;
|
|
156
156
|
/**
|
|
157
157
|
* Create new item(s) in a table
|
|
158
158
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
import { randomBytes, scryptSync } from "node:crypto";
|
|
3
3
|
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import { glob, mkdir,
|
|
4
|
+
import { glob, mkdir, readdir, readFile, rename, rm, unlink, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { join, parse } from "node:path";
|
|
6
6
|
import { inspect } from "node:util";
|
|
7
7
|
import Inison from "inison";
|
|
@@ -1149,6 +1149,7 @@ export default class Inibase {
|
|
|
1149
1149
|
options.columns = options.columns || [];
|
|
1150
1150
|
options.page = options.page || 1;
|
|
1151
1151
|
options.perPage = options.perPage || 15;
|
|
1152
|
+
let total;
|
|
1152
1153
|
let RETURN;
|
|
1153
1154
|
let schema = structuredClone((await this.getTable(tableName)).schema);
|
|
1154
1155
|
if (!schema)
|
|
@@ -1345,6 +1346,12 @@ export default class Inibase {
|
|
|
1345
1346
|
.map(({ id }) => id);
|
|
1346
1347
|
RETURN = Object.values(Utils.deepMerge(LineNumberDataObj, await this.processSchemaData(tableName, Utils.filterSchema(schema, (field) => !alreadyExistsColumnsIDs.includes(field.id) ||
|
|
1347
1348
|
Utils.isFieldType(field, "table")), Object.keys(LineNumberDataObj).map(Number), options)));
|
|
1349
|
+
total = Math.min(...[...this.totalItems.entries()]
|
|
1350
|
+
.filter(([k]) => k.startsWith(`${tableName}-`))
|
|
1351
|
+
.map(([, v]) => v));
|
|
1352
|
+
for (const [key] of this.totalItems)
|
|
1353
|
+
if (key.startsWith(`${tableName}-`) && key !== `${tableName}-id`)
|
|
1354
|
+
this.totalItems.delete(key);
|
|
1348
1355
|
if (globalConfig[this.databasePath].tables.get(tableName).config.cache)
|
|
1349
1356
|
await writeFile(cachedFilePath, Object.keys(LineNumberDataObj).join(","));
|
|
1350
1357
|
}
|
|
@@ -1353,12 +1360,7 @@ export default class Inibase {
|
|
|
1353
1360
|
(Utils.isObject(RETURN) && !Object.keys(RETURN).length) ||
|
|
1354
1361
|
(Array.isArray(RETURN) && !RETURN.length))
|
|
1355
1362
|
return null;
|
|
1356
|
-
|
|
1357
|
-
if (Utils.isObject(where))
|
|
1358
|
-
total = Math.min(...[...this.totalItems.entries()]
|
|
1359
|
-
.filter(([k]) => k.startsWith(`${tableName}-`))
|
|
1360
|
-
.map(([, v]) => v));
|
|
1361
|
-
else
|
|
1363
|
+
if (total === undefined)
|
|
1362
1364
|
total = this.totalItems.has(`${tableName}-*`)
|
|
1363
1365
|
? this.totalItems.get(`${tableName}-*`)
|
|
1364
1366
|
: Math.max(...[...this.totalItems.entries()]
|
|
@@ -1368,7 +1370,7 @@ export default class Inibase {
|
|
|
1368
1370
|
...(({ columns, ...restOfOptions }) => restOfOptions)(options),
|
|
1369
1371
|
perPage: Array.isArray(RETURN) ? RETURN.length : 1,
|
|
1370
1372
|
totalPages: options.perPage < 0 ? 1 : Math.ceil(total / options.perPage),
|
|
1371
|
-
total
|
|
1373
|
+
total,
|
|
1372
1374
|
};
|
|
1373
1375
|
return onlyOne && Array.isArray(RETURN) ? RETURN[0] : RETURN;
|
|
1374
1376
|
}
|
package/dist/utils.js
CHANGED
|
@@ -64,7 +64,7 @@ export const isNumber = (input) => {
|
|
|
64
64
|
return false;
|
|
65
65
|
};
|
|
66
66
|
// As a literal (no double-escaping).
|
|
67
|
-
const emailPattern = /^[A-Za-z0-9!#%&'
|
|
67
|
+
const emailPattern = /^[A-Za-z0-9!#%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
|
|
68
68
|
/**
|
|
69
69
|
* Checks if the input is a valid email format.
|
|
70
70
|
*
|
|
@@ -566,7 +566,7 @@ export const unsetField = (keyPath, schema) => {
|
|
|
566
566
|
export function toDotNotation(obj, skipKeys, currentPath = "") {
|
|
567
567
|
const result = {};
|
|
568
568
|
for (const key in obj) {
|
|
569
|
-
if (Object.
|
|
569
|
+
if (Object.hasOwn(obj, key)) {
|
|
570
570
|
const value = obj[key];
|
|
571
571
|
const newKey = currentPath ? `${currentPath}.${key}` : key;
|
|
572
572
|
if (skipKeys?.includes(key.toLowerCase())) {
|
package/dist/utils.server.js
CHANGED
|
@@ -3,10 +3,10 @@ import { execFile as execFileSync, exec as execSync } from "node:child_process";
|
|
|
3
3
|
import { createCipheriv, createDecipheriv, createHash, randomBytes, scryptSync, } from "node:crypto";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { gunzip as gunzipSync, gzip as gzipSync } from "node:zlib";
|
|
6
|
+
import Inison from "inison";
|
|
6
7
|
import RE2 from "re2";
|
|
7
8
|
import { globalConfig } from "./index.js";
|
|
8
9
|
import { detectFieldType, isNumber, isPassword } from "./utils.js";
|
|
9
|
-
import Inison from "inison";
|
|
10
10
|
export const exec = promisify(execSync);
|
|
11
11
|
export const execFile = promisify(execFileSync);
|
|
12
12
|
export const gzip = promisify(gzipSync);
|