inibase 1.0.0-rc.36 → 1.0.0-rc.37

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.
Binary file
package/dist/file.js CHANGED
@@ -1,4 +1,4 @@
1
- import { open, access, writeFile, readFile, constants as fsConstants, unlink, stat, } from "node:fs/promises";
1
+ import { open, access, writeFile, readFile, constants as fsConstants, unlink, } 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";
@@ -314,7 +314,7 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
314
314
  */
315
315
  export const replace = async (filePath, replacements) => {
316
316
  const fileTempPath = filePath.replace(/([^/]+)\/?$/, `.tmp/$1`);
317
- if ((await isExists(filePath)) && (await stat(filePath)).size > 1) {
317
+ if (await isExists(filePath)) {
318
318
  let fileHandle, fileTempHandle, rl;
319
319
  try {
320
320
  let linesCount = 0;
@@ -367,7 +367,7 @@ export const replace = async (filePath, replacements) => {
367
367
  */
368
368
  export const append = async (filePath, data) => {
369
369
  const fileTempPath = filePath.replace(/([^/]+)\/?$/, `.tmp/$1`);
370
- if ((await isExists(filePath)) && (await stat(filePath)).size > 1) {
370
+ if (await isExists(filePath)) {
371
371
  let fileHandle, fileTempHandle, rl;
372
372
  try {
373
373
  fileHandle = await open(filePath, "r");
@@ -378,7 +378,8 @@ export const append = async (filePath, data) => {
378
378
  transform(line, encoding, callback) {
379
379
  if (!isAppended) {
380
380
  isAppended = true;
381
- return callback(null, `${Array.isArray(data) ? data.join("\n") : data}\n${line}\n`);
381
+ return callback(null, `${Array.isArray(data) ? data.join("\n") : data}\n` +
382
+ (line.length ? `${line}\n` : ""));
382
383
  }
383
384
  else
384
385
  return callback(null, `${line}\n`);
@@ -406,18 +407,25 @@ export const append = async (filePath, data) => {
406
407
  * Note: Creates a temporary file during the process and replaces the original file with it after removing lines.
407
408
  */
408
409
  export const remove = async (filePath, linesToDelete) => {
409
- let linesCount = 0;
410
+ let linesCount = 0, deletedCount = 0;
410
411
  const fileHandle = await open(filePath, "r"), fileTempPath = filePath.replace(/([^/]+)\/?$/, `.tmp/$1`), fileTempHandle = await open(fileTempPath, "w"), linesToDeleteArray = new Set(Array.isArray(linesToDelete)
411
412
  ? linesToDelete.map(Number)
412
413
  : [Number(linesToDelete)]), rl = readLineInternface(fileHandle);
413
414
  await _pipeline(rl, fileTempHandle.createWriteStream(), new Transform({
414
415
  transform(line, encoding, callback) {
415
416
  linesCount++;
416
- if (linesToDeleteArray.has(linesCount))
417
+ if (linesToDeleteArray.has(linesCount)) {
418
+ deletedCount++;
417
419
  return callback();
420
+ }
418
421
  else
419
422
  return callback(null, `${line}\n`);
420
423
  },
424
+ final(callback) {
425
+ if (deletedCount === linesCount)
426
+ this.push("\n");
427
+ return callback();
428
+ },
421
429
  }));
422
430
  await fileTempHandle.close();
423
431
  await fileHandle.close();
@@ -636,7 +644,7 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
636
644
  export const count = async (filePath) => {
637
645
  // return Number((await exec(`wc -l < ${filePath}`)).stdout.trim());
638
646
  let linesCount = 0;
639
- if ((await isExists(filePath)) && (await stat(filePath)).size > 1) {
647
+ if (await isExists(filePath)) {
640
648
  let fileHandle, rl;
641
649
  try {
642
650
  (fileHandle = await open(filePath, "r")),
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export default class Inibase {
23
23
  this.pageInfo = {};
24
24
  if (!existsSync(".env") || !process.env.INIBASE_SECRET) {
25
25
  this.salt = scryptSync(randomBytes(16), randomBytes(16), 32);
26
- appendFileSync(".env", `INIBASE_SECRET=${this.salt.toString("hex")}\n`);
26
+ appendFileSync(".env", `\nINIBASE_SECRET=${this.salt.toString("hex")}\n`);
27
27
  }
28
28
  else
29
29
  this.salt = Buffer.from(process.env.INIBASE_SECRET, "hex");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.36",
3
+ "version": "1.0.0-rc.37",
4
4
  "author": {
5
5
  "name": "Karim Amahtil",
6
6
  "email": "karim.amahtil@gmail.com"