inibase 1.0.0-rc.60 → 1.0.0-rc.62
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 +111 -78
- package/dist/cli.js +12 -9
- package/dist/file.d.ts +3 -3
- package/dist/file.js +119 -147
- package/dist/index.d.ts +20 -11
- package/dist/index.js +203 -156
- package/dist/utils.d.ts +1 -3
- package/dist/utils.js +37 -1
- package/dist/utils.server.d.ts +5 -0
- package/dist/utils.server.js +6 -3
- package/package.json +1 -1
package/dist/file.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { open, access, writeFile, readFile, constants as fsConstants, unlink, copyFile, appendFile,
|
|
1
|
+
import { open, access, writeFile, readFile, constants as fsConstants, unlink, copyFile, appendFile, } from "node:fs/promises";
|
|
2
2
|
import { createInterface } from "node:readline";
|
|
3
3
|
import { Transform } from "node:stream";
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
5
|
-
import { createGzip, createGunzip
|
|
6
|
-
import {
|
|
7
|
-
import { detectFieldType, isArrayOfObjects, isJSON, isNumber, isObject, } from "./utils.js";
|
|
8
|
-
import { encodeID, compare, exec } from "./utils.server.js";
|
|
9
|
-
import * as Config from "./config.js";
|
|
5
|
+
import { createGzip, createGunzip } from "node:zlib";
|
|
6
|
+
import { join } from "node:path";
|
|
10
7
|
import Inison from "inison";
|
|
8
|
+
import { detectFieldType, isArrayOfObjects, isJSON, isNumber, isObject, } from "./utils.js";
|
|
9
|
+
import { encodeID, compare, exec, gzip, gunzip } from "./utils.server.js";
|
|
11
10
|
export const lock = async (folderPath, prefix) => {
|
|
12
11
|
let lockFile = null;
|
|
13
12
|
const lockFilePath = join(folderPath, `${prefix ?? ""}.locked`);
|
|
@@ -29,17 +28,14 @@ export const unlock = async (folderPath, prefix) => {
|
|
|
29
28
|
}
|
|
30
29
|
catch { }
|
|
31
30
|
};
|
|
32
|
-
export const write = async (filePath, data
|
|
33
|
-
await
|
|
34
|
-
await writeFile(filePath, Config.isCompressionEnabled && !disableCompression
|
|
35
|
-
? gzipSync(String(data))
|
|
36
|
-
: String(data));
|
|
31
|
+
export const write = async (filePath, data) => {
|
|
32
|
+
await writeFile(filePath, filePath.endsWith(".gz") ? await gzip(data) : data);
|
|
37
33
|
};
|
|
38
|
-
export const read = async (filePath
|
|
39
|
-
?
|
|
40
|
-
:
|
|
41
|
-
const _pipeline = async (rl, writeStream, transform) => {
|
|
42
|
-
if (
|
|
34
|
+
export const read = async (filePath) => filePath.endsWith(".gz")
|
|
35
|
+
? (await gunzip(await readFile(filePath, "utf8"))).toString()
|
|
36
|
+
: await readFile(filePath, "utf8");
|
|
37
|
+
const _pipeline = async (filePath, rl, writeStream, transform) => {
|
|
38
|
+
if (filePath.endsWith(".gz"))
|
|
43
39
|
await pipeline(rl, transform, createGzip(), writeStream);
|
|
44
40
|
else
|
|
45
41
|
await pipeline(rl, transform, writeStream);
|
|
@@ -50,8 +46,8 @@ const _pipeline = async (rl, writeStream, transform) => {
|
|
|
50
46
|
* @param fileHandle - The file handle from which to create a read stream.
|
|
51
47
|
* @returns A readline.Interface instance configured with the provided file stream.
|
|
52
48
|
*/
|
|
53
|
-
const
|
|
54
|
-
input:
|
|
49
|
+
const createReadLineInternface = (filePath, fileHandle) => createInterface({
|
|
50
|
+
input: filePath.endsWith(".gz")
|
|
55
51
|
? fileHandle.createReadStream().pipe(createGunzip())
|
|
56
52
|
: fileHandle.createReadStream(),
|
|
57
53
|
crlfDelay: Number.POSITIVE_INFINITY,
|
|
@@ -182,11 +178,9 @@ export const decode = (input, fieldType, fieldChildrenType, secretKey) => {
|
|
|
182
178
|
};
|
|
183
179
|
export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, secretKey, readWholeFile = false) {
|
|
184
180
|
let fileHandle = null;
|
|
185
|
-
let rl = null;
|
|
186
181
|
try {
|
|
187
182
|
fileHandle = await open(filePath, "r");
|
|
188
|
-
rl =
|
|
189
|
-
const lines = {};
|
|
183
|
+
const rl = createReadLineInternface(filePath, fileHandle), lines = {};
|
|
190
184
|
let linesCount = 0;
|
|
191
185
|
if (!lineNumbers) {
|
|
192
186
|
for await (const line of rl) {
|
|
@@ -194,17 +188,17 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
|
|
|
194
188
|
lines[linesCount] = decode(line, fieldType, fieldChildrenType, secretKey);
|
|
195
189
|
}
|
|
196
190
|
}
|
|
197
|
-
else if (lineNumbers
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (lastLine)
|
|
204
|
-
lines[linesCount] = decode(lastLine, fieldType, fieldChildrenType, secretKey);
|
|
191
|
+
else if (lineNumbers == -1) {
|
|
192
|
+
const command = filePath.endsWith(".gz")
|
|
193
|
+
? `zcat ${filePath} | sed -n '$p'`
|
|
194
|
+
: `sed -n '$p' ${filePath}`, foundedLine = (await exec(command)).stdout.trim();
|
|
195
|
+
if (foundedLine)
|
|
196
|
+
lines[linesCount] = decode(foundedLine, fieldType, fieldChildrenType, secretKey);
|
|
205
197
|
}
|
|
206
198
|
else {
|
|
207
199
|
lineNumbers = Array.isArray(lineNumbers) ? lineNumbers : [lineNumbers];
|
|
200
|
+
if (lineNumbers.some(Number.isNaN))
|
|
201
|
+
throw new Error("UNVALID_LINE_NUMBERS");
|
|
208
202
|
if (readWholeFile) {
|
|
209
203
|
const lineNumbersArray = new Set(lineNumbers);
|
|
210
204
|
for await (const line of rl) {
|
|
@@ -216,9 +210,9 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
|
|
|
216
210
|
}
|
|
217
211
|
return [lines, linesCount];
|
|
218
212
|
}
|
|
219
|
-
const command =
|
|
213
|
+
const command = filePath.endsWith(".gz")
|
|
220
214
|
? `zcat ${filePath} | sed -n '${lineNumbers.join("p;")}p'`
|
|
221
|
-
: `sed -n '${lineNumbers.join("p;")}p' ${filePath}`, foundedLines = (await exec(command)).stdout.trim().split(
|
|
215
|
+
: `sed -n '${lineNumbers.join("p;")}p' ${filePath}`, foundedLines = (await exec(command)).stdout.trim().split("\n");
|
|
222
216
|
let index = 0;
|
|
223
217
|
for (const line of foundedLines) {
|
|
224
218
|
lines[lineNumbers[index]] = decode(line, fieldType, fieldChildrenType, secretKey);
|
|
@@ -229,7 +223,6 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
|
|
|
229
223
|
}
|
|
230
224
|
finally {
|
|
231
225
|
// Ensure that file handles are closed, even if an error occurred
|
|
232
|
-
rl?.close();
|
|
233
226
|
await fileHandle?.close();
|
|
234
227
|
}
|
|
235
228
|
}
|
|
@@ -248,13 +241,12 @@ export const replace = async (filePath, replacements) => {
|
|
|
248
241
|
if (await isExists(filePath)) {
|
|
249
242
|
let fileHandle = null;
|
|
250
243
|
let fileTempHandle = null;
|
|
251
|
-
let rl = null;
|
|
252
244
|
try {
|
|
253
245
|
let linesCount = 0;
|
|
254
246
|
fileHandle = await open(filePath, "r");
|
|
255
247
|
fileTempHandle = await open(fileTempPath, "w");
|
|
256
|
-
rl =
|
|
257
|
-
await _pipeline(rl, fileTempHandle.createWriteStream(), new Transform({
|
|
248
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
249
|
+
await _pipeline(filePath, rl, fileTempHandle.createWriteStream(), new Transform({
|
|
258
250
|
transform(line, encoding, callback) {
|
|
259
251
|
linesCount++;
|
|
260
252
|
const replacement = isObject(replacements)
|
|
@@ -269,7 +261,6 @@ export const replace = async (filePath, replacements) => {
|
|
|
269
261
|
}
|
|
270
262
|
finally {
|
|
271
263
|
// Ensure that file handles are closed, even if an error occurred
|
|
272
|
-
rl?.close();
|
|
273
264
|
await fileHandle?.close();
|
|
274
265
|
await fileTempHandle?.close();
|
|
275
266
|
}
|
|
@@ -297,23 +288,22 @@ export const replace = async (filePath, replacements) => {
|
|
|
297
288
|
* @returns Promise<string[]>. Modifies the file by appending data.
|
|
298
289
|
*
|
|
299
290
|
*/
|
|
300
|
-
export const append = async (filePath, data) => {
|
|
291
|
+
export const append = async (filePath, data, prepend) => {
|
|
301
292
|
const fileTempPath = filePath.replace(/([^/]+)\/?$/, ".tmp/$1");
|
|
302
293
|
if (await isExists(filePath)) {
|
|
303
|
-
if (!
|
|
294
|
+
if (!prepend && !filePath.endsWith(".gz")) {
|
|
304
295
|
await copyFile(filePath, fileTempPath);
|
|
305
296
|
await appendFile(fileTempPath, `${Array.isArray(data) ? data.join("\n") : data}\n`);
|
|
306
297
|
}
|
|
307
298
|
else {
|
|
308
299
|
let fileHandle = null;
|
|
309
300
|
let fileTempHandle = null;
|
|
310
|
-
let rl = null;
|
|
311
301
|
try {
|
|
312
302
|
fileHandle = await open(filePath, "r");
|
|
313
303
|
fileTempHandle = await open(fileTempPath, "w");
|
|
314
|
-
rl =
|
|
304
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
315
305
|
let isAppended = false;
|
|
316
|
-
await _pipeline(rl, fileTempHandle.createWriteStream(), new Transform({
|
|
306
|
+
await _pipeline(filePath, rl, fileTempHandle.createWriteStream(), new Transform({
|
|
317
307
|
transform(line, _, callback) {
|
|
318
308
|
if (!isAppended) {
|
|
319
309
|
isAppended = true;
|
|
@@ -325,14 +315,13 @@ export const append = async (filePath, data) => {
|
|
|
325
315
|
}
|
|
326
316
|
finally {
|
|
327
317
|
// Ensure that file handles are closed, even if an error occurred
|
|
328
|
-
rl?.close();
|
|
329
318
|
await fileHandle?.close();
|
|
330
319
|
await fileTempHandle?.close();
|
|
331
320
|
}
|
|
332
321
|
}
|
|
333
322
|
}
|
|
334
323
|
else
|
|
335
|
-
await write(fileTempPath, `${Array.isArray(data) ? data.join("\n") : data}\n
|
|
324
|
+
await write(fileTempPath, `${Array.isArray(data) ? data.join("\n") : data}\n`);
|
|
336
325
|
return [fileTempPath, filePath];
|
|
337
326
|
};
|
|
338
327
|
/**
|
|
@@ -348,38 +337,13 @@ export const remove = async (filePath, linesToDelete) => {
|
|
|
348
337
|
linesToDelete = Array.isArray(linesToDelete)
|
|
349
338
|
? linesToDelete.map(Number)
|
|
350
339
|
: [Number(linesToDelete)];
|
|
340
|
+
if (linesToDelete.some(Number.isNaN))
|
|
341
|
+
throw new Error("UNVALID_LINE_NUMBERS");
|
|
351
342
|
const fileTempPath = filePath.replace(/([^/]+)\/?$/, ".tmp/$1");
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
await exec(command);
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
let linesCount = 0;
|
|
360
|
-
let deletedCount = 0;
|
|
361
|
-
const fileHandle = await open(filePath, "r");
|
|
362
|
-
const fileTempHandle = await open(fileTempPath, "w");
|
|
363
|
-
const linesToDeleteArray = new Set(linesToDelete);
|
|
364
|
-
const rl = readLineInternface(fileHandle);
|
|
365
|
-
await _pipeline(rl, fileTempHandle.createWriteStream(), new Transform({
|
|
366
|
-
transform(line, _, callback) {
|
|
367
|
-
linesCount++;
|
|
368
|
-
if (linesToDeleteArray.has(linesCount)) {
|
|
369
|
-
deletedCount++;
|
|
370
|
-
return callback();
|
|
371
|
-
}
|
|
372
|
-
return callback(null, `${line}\n`);
|
|
373
|
-
},
|
|
374
|
-
final(callback) {
|
|
375
|
-
if (deletedCount === linesCount)
|
|
376
|
-
this.push("\n");
|
|
377
|
-
return callback();
|
|
378
|
-
},
|
|
379
|
-
}));
|
|
380
|
-
await fileTempHandle.close();
|
|
381
|
-
await fileHandle.close();
|
|
382
|
-
}
|
|
343
|
+
const command = filePath.endsWith(".gz")
|
|
344
|
+
? `zcat ${filePath} | sed "${linesToDelete.join("d;")}d" | gzip > ${fileTempPath}`
|
|
345
|
+
: `sed "${linesToDelete.join("d;")}d" ${filePath} > ${fileTempPath}`;
|
|
346
|
+
await exec(command);
|
|
383
347
|
return [fileTempPath, filePath];
|
|
384
348
|
};
|
|
385
349
|
/**
|
|
@@ -409,12 +373,11 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
|
|
|
409
373
|
let foundItems = 0;
|
|
410
374
|
const linesNumbers = new Set();
|
|
411
375
|
let fileHandle = null;
|
|
412
|
-
let rl = null;
|
|
413
376
|
try {
|
|
414
377
|
// Open the file for reading.
|
|
415
378
|
fileHandle = await open(filePath, "r");
|
|
416
379
|
// Create a Readline interface to read the file line by line.
|
|
417
|
-
rl =
|
|
380
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
418
381
|
// Iterate through each line in the file.
|
|
419
382
|
for await (const line of rl) {
|
|
420
383
|
// Increment the line count for each line.
|
|
@@ -454,7 +417,6 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
|
|
|
454
417
|
}
|
|
455
418
|
finally {
|
|
456
419
|
// Close the file handle in the finally block to ensure it is closed even if an error occurs.
|
|
457
|
-
rl?.close();
|
|
458
420
|
await fileHandle?.close();
|
|
459
421
|
}
|
|
460
422
|
};
|
|
@@ -471,15 +433,13 @@ export const count = async (filePath) => {
|
|
|
471
433
|
let linesCount = 0;
|
|
472
434
|
if (await isExists(filePath)) {
|
|
473
435
|
let fileHandle = null;
|
|
474
|
-
let rl = null;
|
|
475
436
|
try {
|
|
476
437
|
fileHandle = await open(filePath, "r");
|
|
477
|
-
rl =
|
|
438
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
478
439
|
for await (const _ of rl)
|
|
479
440
|
linesCount++;
|
|
480
441
|
}
|
|
481
442
|
finally {
|
|
482
|
-
rl?.close();
|
|
483
443
|
await fileHandle?.close();
|
|
484
444
|
}
|
|
485
445
|
}
|
|
@@ -495,27 +455,31 @@ export const count = async (filePath) => {
|
|
|
495
455
|
* Note: Decodes each line as a number using the 'decode' function. Non-numeric lines contribute 0 to the sum.
|
|
496
456
|
*/
|
|
497
457
|
export const sum = async (filePath, lineNumbers) => {
|
|
498
|
-
let sum = 0;
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
458
|
+
let sum = 0, fileHandle = null;
|
|
459
|
+
try {
|
|
460
|
+
fileHandle = await open(filePath, "r");
|
|
461
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
462
|
+
if (lineNumbers) {
|
|
463
|
+
let linesCount = 0;
|
|
464
|
+
const lineNumbersArray = new Set(Array.isArray(lineNumbers) ? lineNumbers : [lineNumbers]);
|
|
465
|
+
for await (const line of rl) {
|
|
466
|
+
linesCount++;
|
|
467
|
+
if (!lineNumbersArray.has(linesCount))
|
|
468
|
+
continue;
|
|
469
|
+
sum += +(decode(line, "number") ?? 0);
|
|
470
|
+
lineNumbersArray.delete(linesCount);
|
|
471
|
+
if (!lineNumbersArray.size)
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
512
474
|
}
|
|
475
|
+
else
|
|
476
|
+
for await (const line of rl)
|
|
477
|
+
sum += +(decode(line, "number") ?? 0);
|
|
478
|
+
return sum;
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
await fileHandle?.close();
|
|
513
482
|
}
|
|
514
|
-
else
|
|
515
|
-
for await (const line of rl)
|
|
516
|
-
sum += +(decode(line, "number") ?? 0);
|
|
517
|
-
await fileHandle.close();
|
|
518
|
-
return sum;
|
|
519
483
|
};
|
|
520
484
|
/**
|
|
521
485
|
* Asynchronously finds the maximum numerical value from specified lines in a file.
|
|
@@ -527,32 +491,36 @@ export const sum = async (filePath, lineNumbers) => {
|
|
|
527
491
|
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the maximum.
|
|
528
492
|
*/
|
|
529
493
|
export const max = async (filePath, lineNumbers) => {
|
|
530
|
-
let max = 0;
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
494
|
+
let max = 0, fileHandle = null, rl = null;
|
|
495
|
+
try {
|
|
496
|
+
fileHandle = await open(filePath, "r");
|
|
497
|
+
rl = createReadLineInternface(filePath, fileHandle);
|
|
498
|
+
if (lineNumbers) {
|
|
499
|
+
let linesCount = 0;
|
|
500
|
+
const lineNumbersArray = new Set(Array.isArray(lineNumbers) ? lineNumbers : [lineNumbers]);
|
|
501
|
+
for await (const line of rl) {
|
|
502
|
+
linesCount++;
|
|
503
|
+
if (!lineNumbersArray.has(linesCount))
|
|
504
|
+
continue;
|
|
505
|
+
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
506
|
+
if (lineContentNum > max)
|
|
507
|
+
max = lineContentNum;
|
|
508
|
+
lineNumbersArray.delete(linesCount);
|
|
509
|
+
if (!lineNumbersArray.size)
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
546
512
|
}
|
|
513
|
+
else
|
|
514
|
+
for await (const line of rl) {
|
|
515
|
+
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
516
|
+
if (lineContentNum > max)
|
|
517
|
+
max = lineContentNum;
|
|
518
|
+
}
|
|
519
|
+
return max;
|
|
520
|
+
}
|
|
521
|
+
finally {
|
|
522
|
+
await fileHandle?.close();
|
|
547
523
|
}
|
|
548
|
-
else
|
|
549
|
-
for await (const line of rl) {
|
|
550
|
-
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
551
|
-
if (lineContentNum > max)
|
|
552
|
-
max = lineContentNum;
|
|
553
|
-
}
|
|
554
|
-
await fileHandle.close();
|
|
555
|
-
return max;
|
|
556
524
|
};
|
|
557
525
|
/**
|
|
558
526
|
* Asynchronously finds the minimum numerical value from specified lines in a file.
|
|
@@ -564,30 +532,34 @@ export const max = async (filePath, lineNumbers) => {
|
|
|
564
532
|
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the minimum.
|
|
565
533
|
*/
|
|
566
534
|
export const min = async (filePath, lineNumbers) => {
|
|
567
|
-
let min = 0;
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
535
|
+
let min = 0, fileHandle = null;
|
|
536
|
+
try {
|
|
537
|
+
fileHandle = await open(filePath, "r");
|
|
538
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
539
|
+
if (lineNumbers) {
|
|
540
|
+
let linesCount = 0;
|
|
541
|
+
const lineNumbersArray = new Set(Array.isArray(lineNumbers) ? lineNumbers : [lineNumbers]);
|
|
542
|
+
for await (const line of rl) {
|
|
543
|
+
linesCount++;
|
|
544
|
+
if (!lineNumbersArray.has(linesCount))
|
|
545
|
+
continue;
|
|
546
|
+
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
547
|
+
if (lineContentNum < min)
|
|
548
|
+
min = lineContentNum;
|
|
549
|
+
lineNumbersArray.delete(linesCount);
|
|
550
|
+
if (!lineNumbersArray.size)
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
583
553
|
}
|
|
554
|
+
else
|
|
555
|
+
for await (const line of rl) {
|
|
556
|
+
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
557
|
+
if (lineContentNum < min)
|
|
558
|
+
min = lineContentNum;
|
|
559
|
+
}
|
|
560
|
+
return min;
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
await fileHandle?.close();
|
|
584
564
|
}
|
|
585
|
-
else
|
|
586
|
-
for await (const line of rl) {
|
|
587
|
-
const lineContentNum = +(decode(line, "number") ?? 0);
|
|
588
|
-
if (lineContentNum < min)
|
|
589
|
-
min = lineContentNum;
|
|
590
|
-
}
|
|
591
|
-
await fileHandle.close();
|
|
592
|
-
return min;
|
|
593
565
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,15 @@ export interface Options {
|
|
|
23
23
|
columns?: string[] | string;
|
|
24
24
|
order?: Record<string, "asc" | "desc">;
|
|
25
25
|
}
|
|
26
|
+
export interface Config {
|
|
27
|
+
compression: boolean;
|
|
28
|
+
cache: boolean;
|
|
29
|
+
prepend: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface TableObject {
|
|
32
|
+
schema?: Schema;
|
|
33
|
+
config: Config;
|
|
34
|
+
}
|
|
26
35
|
export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
|
|
27
36
|
type pageInfo = {
|
|
28
37
|
total?: number;
|
|
@@ -41,24 +50,25 @@ declare global {
|
|
|
41
50
|
entries<T extends object>(o: T): Entries<T>;
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
|
-
export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "NO_RESULTS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS" | "NO_ENV";
|
|
53
|
+
export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "NO_RESULTS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS" | "NO_ENV" | "TABLE_EXISTS" | "TABLE_NOT_EXISTS";
|
|
45
54
|
export type ErrorLang = "en";
|
|
46
55
|
export default class Inibase {
|
|
47
|
-
folder: string;
|
|
48
|
-
database: string;
|
|
49
|
-
table: string | null;
|
|
50
56
|
pageInfo: Record<string, pageInfo>;
|
|
57
|
+
salt: Buffer;
|
|
58
|
+
private databasePath;
|
|
59
|
+
private tables;
|
|
51
60
|
private fileExtension;
|
|
52
61
|
private checkIFunique;
|
|
53
62
|
private totalItems;
|
|
54
|
-
|
|
55
|
-
constructor(database: string, mainFolder?: string, _table?: string | null, _totalItems?: Record<string, number>, _pageInfo?: Record<string, pageInfo>, _isThreadEnabled?: boolean);
|
|
63
|
+
constructor(database: string, mainFolder?: string);
|
|
56
64
|
private throwError;
|
|
57
65
|
private getFileExtension;
|
|
58
66
|
private _schemaToIdsPath;
|
|
59
|
-
|
|
67
|
+
createTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
|
|
68
|
+
updateTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
|
|
69
|
+
getTable(tableName: string): Promise<TableObject>;
|
|
60
70
|
getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
|
|
61
|
-
private
|
|
71
|
+
private throwErrorIfTableEmpty;
|
|
62
72
|
private validateData;
|
|
63
73
|
private formatField;
|
|
64
74
|
private checkUnique;
|
|
@@ -66,15 +76,14 @@ export default class Inibase {
|
|
|
66
76
|
private getDefaultValue;
|
|
67
77
|
private _combineObjectsToArray;
|
|
68
78
|
private _CombineData;
|
|
69
|
-
private _addPathToKeys;
|
|
70
79
|
private joinPathesContents;
|
|
71
80
|
private _getItemsFromSchemaHelper;
|
|
72
81
|
private getItemsFromSchema;
|
|
73
82
|
private applyCriteria;
|
|
74
83
|
private _filterSchemaByColumns;
|
|
75
84
|
clearCache(tablePath: string): Promise<void>;
|
|
76
|
-
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined,
|
|
77
|
-
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true,
|
|
85
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined, _skipIdColumn?: boolean): Promise<Data | null>;
|
|
86
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true, _skipIdColumn?: boolean): Promise<number[]>;
|
|
78
87
|
post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
|
|
79
88
|
post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
|
|
80
89
|
post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
|