inibase 1.0.0-rc.103 → 1.0.0-rc.105

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/file.d.ts CHANGED
@@ -3,6 +3,7 @@ export declare const lock: (folderPath: string, prefix?: string) => Promise<void
3
3
  export declare const unlock: (folderPath: string, prefix?: string) => Promise<void>;
4
4
  export declare const write: (filePath: string, data: any) => Promise<void>;
5
5
  export declare const read: (filePath: string) => Promise<string>;
6
+ export declare function escapeShellPath(filePath: string): string;
6
7
  /**
7
8
  * Checks if a file or directory exists at the specified path.
8
9
  *
package/dist/file.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createWriteStream } from "node:fs";
2
2
  import { access, appendFile, copyFile, constants as fsConstants, open, readFile, unlink, writeFile, } from "node:fs/promises";
3
- import { join } from "node:path";
3
+ import { join, resolve } from "node:path";
4
4
  import { createInterface } from "node:readline";
5
5
  import { Transform } from "node:stream";
6
6
  import { pipeline } from "node:stream/promises";
@@ -36,9 +36,11 @@ export const write = async (filePath, data) => {
36
36
  export const read = async (filePath) => filePath.endsWith(".gz")
37
37
  ? (await gunzip(await readFile(filePath, "utf8"))).toString()
38
38
  : await readFile(filePath, "utf8");
39
- // Escaping function to safely handle special characters
40
- function _escapeDoubleQuotes(arg) {
41
- return arg.replace(/(["$`\\])/g, "\\$1"); // Escape double quotes, $, `, and \
39
+ export function escapeShellPath(filePath) {
40
+ // Resolve the path to avoid relative path issues
41
+ const resolvedPath = resolve(filePath);
42
+ // Escape double quotes and special shell characters
43
+ return resolvedPath.replace(/(["\\$`])/g, "\\$1");
42
44
  }
43
45
  const _pipeline = async (filePath, rl, writeStream, transform) => {
44
46
  if (filePath.endsWith(".gz"))
@@ -198,7 +200,7 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
198
200
  }
199
201
  }
200
202
  else if (lineNumbers == -1) {
201
- const escapedFilePath = `"${_escapeDoubleQuotes(filePath)}"`;
203
+ const escapedFilePath = `${escapeShellPath(filePath)}`;
202
204
  const command = filePath.endsWith(".gz")
203
205
  ? `zcat ${escapedFilePath} | sed -n '$p'`
204
206
  : `sed -n '$p' ${escapedFilePath}`, foundedLine = (await exec(command)).stdout.trimEnd();
@@ -220,7 +222,7 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
220
222
  }
221
223
  return [lines, linesCount];
222
224
  }
223
- const escapedFilePath = `"${_escapeDoubleQuotes(filePath)}"`;
225
+ const escapedFilePath = `${escapeShellPath(filePath)}`;
224
226
  const command = filePath.endsWith(".gz")
225
227
  ? `zcat "${escapedFilePath}" | sed -n '${lineNumbers.join("p;")}p'`
226
228
  : `sed -n '${lineNumbers.join("p;")}p' "${escapedFilePath}"`, foundedLines = (await exec(command)).stdout.trimEnd().split("\n");
@@ -353,7 +355,7 @@ export const append = async (filePath, data) => {
353
355
  await appendFile(fileTempPath, `${Array.isArray(data) ? data.join("\n") : data}\n`);
354
356
  }
355
357
  else {
356
- const escapedFileTempPath = `"${_escapeDoubleQuotes(fileTempPath)}"`;
358
+ const escapedFileTempPath = `${escapeShellPath(fileTempPath)}`;
357
359
  await exec(`echo $'${(Array.isArray(data) ? data.join("\n") : data)
358
360
  .toString()
359
361
  .replace(/'/g, "\\'")}' | gzip - >> ${escapedFileTempPath}`);
@@ -409,9 +411,9 @@ export const prepend = async (filePath, data) => {
409
411
  const fileChildTempPath = filePath.replace(/([^/]+)\/?$/, ".tmp/tmp_$1");
410
412
  try {
411
413
  await write(fileChildTempPath, `${Array.isArray(data) ? data.join("\n") : data}\n`);
412
- const escapedFilePath = `"${_escapeDoubleQuotes(filePath)}"`;
413
- const escapedFileTempPath = `"${_escapeDoubleQuotes(fileTempPath)}"`;
414
- const escapedFileChildTempPath = `"${_escapeDoubleQuotes(fileChildTempPath)}"`;
414
+ const escapedFilePath = `${escapeShellPath(filePath)}`;
415
+ const escapedFileTempPath = `${escapeShellPath(fileTempPath)}`;
416
+ const escapedFileChildTempPath = `${escapeShellPath(fileChildTempPath)}`;
415
417
  await exec(`cat ${escapedFileChildTempPath} ${escapedFilePath} > ${escapedFileTempPath}`);
416
418
  }
417
419
  catch {
@@ -449,8 +451,8 @@ export const remove = async (filePath, linesToDelete) => {
449
451
  throw new Error("UNVALID_LINE_NUMBERS");
450
452
  const fileTempPath = filePath.replace(/([^/]+)\/?$/, ".tmp/$1");
451
453
  try {
452
- const escapedFilePath = `"${_escapeDoubleQuotes(filePath)}"`;
453
- const escapedFileTempPath = `"${_escapeDoubleQuotes(fileTempPath)}"`;
454
+ const escapedFilePath = `${escapeShellPath(filePath)}`;
455
+ const escapedFileTempPath = `${escapeShellPath(fileTempPath)}`;
454
456
  const command = filePath.endsWith(".gz")
455
457
  ? `zcat ${escapedFilePath} | sed "${linesToDelete.join("d;")}d" | gzip > ${fileTempPath}`
456
458
  : `sed "${linesToDelete.join("d;")}d" ${escapedFilePath} > ${escapedFileTempPath}`;
package/dist/index.js CHANGED
@@ -258,6 +258,7 @@ export default class Inibase {
258
258
  type: "id",
259
259
  required: true,
260
260
  },
261
+ ...schema,
261
262
  {
262
263
  id: -1,
263
264
  key: "createdAt",
@@ -268,9 +269,7 @@ export default class Inibase {
268
269
  id: -2,
269
270
  key: "updatedAt",
270
271
  type: "date",
271
- required: false,
272
272
  },
273
- ...schema,
274
273
  ];
275
274
  if (!encodeIDs)
276
275
  return schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.103",
3
+ "version": "1.0.0-rc.105",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",