inibase 1.7.0 → 1.7.2

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 CHANGED
File without changes
package/dist/index.js CHANGED
@@ -24,7 +24,11 @@ export const ERROR_CODES = [
24
24
  "INVALID_NAME",
25
25
  ];
26
26
  // hide ExperimentalWarning glob()
27
- process.removeAllListeners("warning");
27
+ // Guard against non-Node environments (e.g. accidental import in a browser bundle)
28
+ if (typeof process !== "undefined" &&
29
+ typeof process.removeAllListeners === "function") {
30
+ process.removeAllListeners("warning");
31
+ }
28
32
  export const globalConfig = {};
29
33
  /**
30
34
  * @param {string} database - Database name
@@ -48,7 +52,7 @@ export default class Inibase {
48
52
  this.uniqueMap = new Map();
49
53
  if (!globalConfig[this.databasePath])
50
54
  globalConfig[this.databasePath] = { tables: new Map() };
51
- if (!process.env.INIBASE_SECRET) {
55
+ if (!process?.env.INIBASE_SECRET) {
52
56
  if (existsSync(".env") &&
53
57
  readFileSync(".env").includes("INIBASE_SECRET="))
54
58
  throw this.createError("NO_ENV");
package/dist/utils.d.ts CHANGED
@@ -221,7 +221,9 @@ export declare function addIdToSchema(schema: Schema, startWithID: {
221
221
  /**
222
222
  * Translated error messages for every supported language and error code.
223
223
  * The `{variable}` placeholder is replaced with the relevant value by
224
- * {@link createError}.
224
+ * {@link createError}. `NO_ENV` is resolved lazily by {@link createError}
225
+ * via {@link NO_ENV_MESSAGES} since it depends on the Node.js version and
226
+ * must stay safe to evaluate outside of Node (e.g. in a browser bundle).
225
227
  */
226
228
  export declare const ERROR_MESSAGES: Record<ErrorLang, Record<ErrorCode, string>>;
227
229
  /**
package/dist/utils.js CHANGED
@@ -628,10 +628,29 @@ export function addIdToSchema(schema, startWithID) {
628
628
  const addIdToSchemaHelper = (schema) => schema.map(addIdToField);
629
629
  return addIdToSchemaHelper(clonedSchema);
630
630
  }
631
+ /**
632
+ * Whether the current Node.js runtime supports the `--env-file` CLI flag
633
+ * (added in Node 20.6, stabilized in later versions). Safe to call outside
634
+ * of Node (e.g. in a browser bundle), where it simply returns `false`.
635
+ */
636
+ const supportsEnvFileFlag = () => {
637
+ if (typeof process === "undefined" || !process.versions?.node)
638
+ return false;
639
+ const [major] = process.versions.node.split(".").map(Number);
640
+ return major >= 20;
641
+ };
642
+ const NO_ENV_MESSAGES = {
643
+ en: ["please run with '--env-file=.env'", "please use dotenv"],
644
+ ar: ["يرجى التشغيل باستخدام '--env-file=.env'", "يرجى استخدام dotenv"],
645
+ fr: ["veuillez exécuter avec '--env-file=.env'", "veuillez utiliser dotenv"],
646
+ es: ["por favor ejecute con '--env-file=.env'", "por favor use dotenv"],
647
+ };
631
648
  /**
632
649
  * Translated error messages for every supported language and error code.
633
650
  * The `{variable}` placeholder is replaced with the relevant value by
634
- * {@link createError}.
651
+ * {@link createError}. `NO_ENV` is resolved lazily by {@link createError}
652
+ * via {@link NO_ENV_MESSAGES} since it depends on the Node.js version and
653
+ * must stay safe to evaluate outside of Node (e.g. in a browser bundle).
635
654
  */
636
655
  export const ERROR_MESSAGES = {
637
656
  en: {
@@ -647,9 +666,7 @@ export const ERROR_MESSAGES = {
647
666
  INVALID_PARAMETERS: "The given parameters are not valid",
648
667
  INVALID_REGEX_MATCH: "Field {variable} does not match the expected pattern",
649
668
  INVALID_NAME: "Name {variable} is not valid",
650
- NO_ENV: Number(process.versions.node.split(".").reduce((a, b) => a + b)) >= 26
651
- ? "please run with '--env-file=.env'"
652
- : "please use dotenv",
669
+ NO_ENV: "",
653
670
  },
654
671
  ar: {
655
672
  TABLE_EMPTY: "الجدول {variable} فارغ",
@@ -664,9 +681,7 @@ export const ERROR_MESSAGES = {
664
681
  INVALID_PARAMETERS: "المعلمات المقدمة غير صالحة",
665
682
  INVALID_REGEX_MATCH: "الحقل {variable} لا يتطابق مع النمط المتوقع",
666
683
  INVALID_NAME: "الاسم {variable} غير صالح",
667
- NO_ENV: Number(process.versions.node.split(".").reduce((a, b) => a + b)) >= 26
668
- ? "يرجى التشغيل باستخدام '--env-file=.env'"
669
- : "يرجى استخدام dotenv",
684
+ NO_ENV: "",
670
685
  },
671
686
  fr: {
672
687
  TABLE_EMPTY: "La table {variable} est vide",
@@ -681,9 +696,7 @@ export const ERROR_MESSAGES = {
681
696
  INVALID_PARAMETERS: "Les paramètres donnés ne sont pas valides",
682
697
  INVALID_REGEX_MATCH: "Le champ {variable} ne correspond pas au modèle attendu",
683
698
  INVALID_NAME: "Le nom {variable} n'est pas valide",
684
- NO_ENV: Number(process.versions.node.split(".").reduce((a, b) => a + b)) >= 26
685
- ? "veuillez exécuter avec '--env-file=.env'"
686
- : "veuillez utiliser dotenv",
699
+ NO_ENV: "",
687
700
  },
688
701
  es: {
689
702
  TABLE_EMPTY: "La tabla {variable} está vacía",
@@ -698,9 +711,7 @@ export const ERROR_MESSAGES = {
698
711
  INVALID_PARAMETERS: "Los parámetros proporcionados no son válidos",
699
712
  INVALID_REGEX_MATCH: "El campo {variable} no coincide con el patrón esperado",
700
713
  INVALID_NAME: "El nombre {variable} no es válido",
701
- NO_ENV: Number(process.versions.node.split(".").reduce((a, b) => a + b)) >= 26
702
- ? "por favor ejecute con '--env-file=.env'"
703
- : "por favor use dotenv",
714
+ NO_ENV: "",
704
715
  },
705
716
  };
706
717
  /**
@@ -712,7 +723,9 @@ export const ERROR_MESSAGES = {
712
723
  * @returns An `Error` whose `name` is the error code and `message` is translated.
713
724
  */
714
725
  export const createError = (language, name, variable) => {
715
- const errorMessage = ERROR_MESSAGES[language]?.[name];
726
+ const errorMessage = name === "NO_ENV"
727
+ ? NO_ENV_MESSAGES[language]?.[supportsEnvFileFlag() ? 0 : 1]
728
+ : ERROR_MESSAGES[language]?.[name];
716
729
  if (!errorMessage)
717
730
  return new Error("ERR");
718
731
  const error = new Error(variable
package/package.json CHANGED
@@ -1,92 +1,93 @@
1
1
  {
2
- "name": "inibase",
3
- "version": "1.7.0",
4
- "type": "module",
5
- "author": {
6
- "name": "Karim Amahtil",
7
- "email": "karim.amahtil@gmail.com"
8
- },
9
- "repository": "inicontent/inibase",
10
- "main": "./dist/index.js",
11
- "exports": {
12
- ".": "./dist/index.js",
13
- "./file": "./dist/file.js",
14
- "./utils": "./dist/utils.js",
15
- "./utils.server": "./dist/utils.server.js"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/inicontent/inibase/issues"
19
- },
20
- "description": "A file-based & memory-efficient, serverless, ACID compliant, relational database management system",
21
- "engines": {
22
- "node": ">=22"
23
- },
24
- "files": [
25
- "/dist"
26
- ],
27
- "funding": "https://github.com/sponsors/inicontent",
28
- "homepage": "https://github.com/inicontent/inibase#readme",
29
- "keywords": [
30
- "nosql",
31
- "rdms",
32
- "database",
33
- "db",
34
- "mongoose",
35
- "relational",
36
- "local",
37
- "file",
38
- "storage",
39
- "json",
40
- "sqlite",
41
- "sql",
42
- "supabase",
43
- "better-sqlite",
44
- "mongodb",
45
- "firebase",
46
- "postgresql",
47
- "pocketbase"
48
- ],
49
- "license": "MIT",
50
- "bin": {
51
- "inibase": "./dist/cli.js"
52
- },
53
- "types": "./dist",
54
- "typesVersions": {
55
- "*": {
56
- ".": [
57
- "./dist/index.d.ts"
58
- ],
59
- "file": [
60
- "./dist/file.d.ts"
61
- ],
62
- "utils": [
63
- "./dist/utils.d.ts"
64
- ],
65
- "utils.server": [
66
- "./dist/utils.server.d.ts"
67
- ]
68
- }
69
- },
70
- "devDependencies": {
71
- "@biomejs/biome": "2.3.10",
72
- "@types/bun": "^1.2.10",
73
- "@types/node": "^22.15.2",
74
- "lefthook": "^1.11.11",
75
- "tinybench": "^4.0.1",
76
- "tsx": "^4.19.3",
77
- "typescript": "^5.8.3"
78
- },
79
- "dependencies": {
80
- "dotenv": "^16.5.0",
81
- "inison": "^2.0.1",
82
- "re2": "^1.26.1"
83
- },
84
- "scripts": {
85
- "prepublish": "tsc",
86
- "prebuild": "biome check --write src",
87
- "build": "tsc",
88
- "benchmark": "./benchmark/run.js",
89
- "test": "tsx ./tests/inibase.test.ts",
90
- "test:utils": "tsx ./tests/utils.test.ts"
91
- }
92
- }
2
+ "name": "inibase",
3
+ "version": "1.7.2",
4
+ "type": "module",
5
+ "author": {
6
+ "name": "Karim Amahtil",
7
+ "email": "karim.amahtil@gmail.com"
8
+ },
9
+ "repository": "inicontent/inibase",
10
+ "main": "./dist/index.js",
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./file": "./dist/file.js",
14
+ "./utils": "./dist/utils.js",
15
+ "./utils.server": "./dist/utils.server.js"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/inicontent/inibase/issues"
19
+ },
20
+ "description": "A file-based & memory-efficient, serverless, ACID compliant, relational database management system",
21
+ "engines": {
22
+ "node": ">=22"
23
+ },
24
+ "files": [
25
+ "/dist"
26
+ ],
27
+ "funding": "https://github.com/sponsors/inicontent",
28
+ "homepage": "https://github.com/inicontent/inibase#readme",
29
+ "keywords": [
30
+ "nosql",
31
+ "rdms",
32
+ "database",
33
+ "db",
34
+ "mongoose",
35
+ "relational",
36
+ "local",
37
+ "file",
38
+ "storage",
39
+ "json",
40
+ "sqlite",
41
+ "sql",
42
+ "supabase",
43
+ "better-sqlite",
44
+ "mongodb",
45
+ "firebase",
46
+ "postgresql",
47
+ "pocketbase"
48
+ ],
49
+ "license": "MIT",
50
+ "scripts": {
51
+ "prepublishOnly": "lefthook run pre-push -f",
52
+ "prepublish": "tsc",
53
+ "prebuild": "biome check --write src",
54
+ "build": "tsc",
55
+ "benchmark": "./benchmark/run.js",
56
+ "test": "tsx ./tests/inibase.test.ts",
57
+ "test:utils": "tsx ./tests/utils.test.ts"
58
+ },
59
+ "bin": {
60
+ "inibase": "./dist/cli.js"
61
+ },
62
+ "types": "./dist",
63
+ "typesVersions": {
64
+ "*": {
65
+ ".": [
66
+ "./dist/index.d.ts"
67
+ ],
68
+ "file": [
69
+ "./dist/file.d.ts"
70
+ ],
71
+ "utils": [
72
+ "./dist/utils.d.ts"
73
+ ],
74
+ "utils.server": [
75
+ "./dist/utils.server.d.ts"
76
+ ]
77
+ }
78
+ },
79
+ "devDependencies": {
80
+ "@biomejs/biome": "2.3.10",
81
+ "@types/bun": "^1.2.10",
82
+ "@types/node": "^22.15.2",
83
+ "lefthook": "^1.11.11",
84
+ "tinybench": "^4.0.1",
85
+ "tsx": "^4.19.3",
86
+ "typescript": "^5.8.3"
87
+ },
88
+ "dependencies": {
89
+ "dotenv": "^16.5.0",
90
+ "inison": "^2.0.1",
91
+ "re2": "^1.26.1"
92
+ }
93
+ }