inibase 3.0.0 → 3.1.1
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 +114 -0
- package/dist/expression.d.ts +159 -0
- package/dist/expression.js +495 -0
- package/dist/index.d.ts +63 -1
- package/dist/index.js +676 -7
- package/dist/utils.js +54 -0
- package/package.json +4 -2
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMPUTED_EXPR_MAX_LENGTH } from "./expression.js";
|
|
1
2
|
/**
|
|
2
3
|
* Type guard function to check if the input is an array of objects.
|
|
3
4
|
*
|
|
@@ -663,6 +664,15 @@ export const ERROR_MESSAGES = {
|
|
|
663
664
|
INVALID_REGEX_MATCH: "Field {variable} does not match the expected pattern",
|
|
664
665
|
INVALID_NAME: "Name {variable} is not valid",
|
|
665
666
|
NO_ENV: "No environment file found",
|
|
667
|
+
COMPUTED_FIELD_SYNTAX: "Invalid computed expression syntax in field {variable}",
|
|
668
|
+
COMPUTED_FIELD_UNKNOWN_FIELD: "Field {variable} references unknown field id {variable}",
|
|
669
|
+
COMPUTED_FIELD_INVALID_LINK: "Field {variable} has an invalid link at hop {variable}",
|
|
670
|
+
COMPUTED_FIELD_INVALID_TARGET: "Field {variable} references an invalid target ({variable})",
|
|
671
|
+
COMPUTED_FIELD_CONFLICT: "Field {variable} cannot be computed and required/unique/regex at the same time",
|
|
672
|
+
COMPUTED_FIELD_CYCLE: "Computed fields form a cycle: {variable}",
|
|
673
|
+
COMPUTED_FIELD_SETTABLE: "Field {variable} is computed and cannot be set directly",
|
|
674
|
+
COMPUTED_FIELD_DANGLING_LINK: "Computed field {variable} references a missing row in table {variable}",
|
|
675
|
+
COMPUTED_FIELD_ARITHMETIC: "Computed field {variable} failed evaluation ({variable})",
|
|
666
676
|
},
|
|
667
677
|
ar: {
|
|
668
678
|
TABLE_EMPTY: "الجدول {variable} فارغ",
|
|
@@ -678,6 +688,15 @@ export const ERROR_MESSAGES = {
|
|
|
678
688
|
INVALID_REGEX_MATCH: "الحقل {variable} لا يتطابق مع النمط المتوقع",
|
|
679
689
|
INVALID_NAME: "الاسم {variable} غير صالح",
|
|
680
690
|
NO_ENV: "لم يتم العثور على ملف البيئة",
|
|
691
|
+
COMPUTED_FIELD_SYNTAX: "صيغة الحقل المحسوب غير صالحة في الحقل {variable}",
|
|
692
|
+
COMPUTED_FIELD_UNKNOWN_FIELD: "الحقل {variable} يشير إلى معرف حقل غير معروف {variable}",
|
|
693
|
+
COMPUTED_FIELD_INVALID_LINK: "الحقل {variable} يحتوي على رابط غير صالح عند الخطوة {variable}",
|
|
694
|
+
COMPUTED_FIELD_INVALID_TARGET: "الحقل {variable} يشير إلى هدف غير صالح ({variable})",
|
|
695
|
+
COMPUTED_FIELD_CONFLICT: "لا يمكن أن يكون الحقل {variable} محسوبًا ومطلوبًا/فريدًا/بنمط في نفس الوقت",
|
|
696
|
+
COMPUTED_FIELD_CYCLE: "الحقول المحسوبة تشكل دورة: {variable}",
|
|
697
|
+
COMPUTED_FIELD_SETTABLE: "الحقل {variable} محسوب ولا يمكن تعيينه مباشرة",
|
|
698
|
+
COMPUTED_FIELD_DANGLING_LINK: "الحقل المحسوب {variable} يشير إلى صف غير موجود في الجدول {variable}",
|
|
699
|
+
COMPUTED_FIELD_ARITHMETIC: "فشل تقييم الحقل المحسوب {variable} ({variable})",
|
|
681
700
|
},
|
|
682
701
|
fr: {
|
|
683
702
|
TABLE_EMPTY: "La table {variable} est vide",
|
|
@@ -693,6 +712,15 @@ export const ERROR_MESSAGES = {
|
|
|
693
712
|
INVALID_REGEX_MATCH: "Le champ {variable} ne correspond pas au modèle attendu",
|
|
694
713
|
INVALID_NAME: "Le nom {variable} n'est pas valide",
|
|
695
714
|
NO_ENV: "Aucun fichier d'environnement trouvé",
|
|
715
|
+
COMPUTED_FIELD_SYNTAX: "Syntaxe d'expression calculée invalide pour le champ {variable}",
|
|
716
|
+
COMPUTED_FIELD_UNKNOWN_FIELD: "Le champ {variable} référence un identifiant de champ inconnu {variable}",
|
|
717
|
+
COMPUTED_FIELD_INVALID_LINK: "Le champ {variable} possède un lien invalide à l'étape {variable}",
|
|
718
|
+
COMPUTED_FIELD_INVALID_TARGET: "Le champ {variable} référence une cible invalide ({variable})",
|
|
719
|
+
COMPUTED_FIELD_CONFLICT: "Le champ {variable} ne peut pas être calculé et requis/unique/regex à la fois",
|
|
720
|
+
COMPUTED_FIELD_CYCLE: "Les champs calculés forment un cycle : {variable}",
|
|
721
|
+
COMPUTED_FIELD_SETTABLE: "Le champ {variable} est calculé et ne peut pas être défini directement",
|
|
722
|
+
COMPUTED_FIELD_DANGLING_LINK: "Le champ calculé {variable} référence une ligne manquante dans la table {variable}",
|
|
723
|
+
COMPUTED_FIELD_ARITHMETIC: "L'évaluation du champ calculé {variable} a échoué ({variable})",
|
|
696
724
|
},
|
|
697
725
|
es: {
|
|
698
726
|
TABLE_EMPTY: "La tabla {variable} está vacía",
|
|
@@ -708,6 +736,15 @@ export const ERROR_MESSAGES = {
|
|
|
708
736
|
INVALID_REGEX_MATCH: "El campo {variable} no coincide con el patrón esperado",
|
|
709
737
|
INVALID_NAME: "El nombre {variable} no es válido",
|
|
710
738
|
NO_ENV: "No se encontró el archivo de entorno",
|
|
739
|
+
COMPUTED_FIELD_SYNTAX: "Sintaxis de expresión calculada no válida en el campo {variable}",
|
|
740
|
+
COMPUTED_FIELD_UNKNOWN_FIELD: "El campo {variable} referencia un id de campo desconocido {variable}",
|
|
741
|
+
COMPUTED_FIELD_INVALID_LINK: "El campo {variable} tiene un enlace no válido en el paso {variable}",
|
|
742
|
+
COMPUTED_FIELD_INVALID_TARGET: "El campo {variable} referencia un destino no válido ({variable})",
|
|
743
|
+
COMPUTED_FIELD_CONFLICT: "El campo {variable} no puede ser calculado y requerido/único/regex a la vez",
|
|
744
|
+
COMPUTED_FIELD_CYCLE: "Los campos calculados forman un ciclo: {variable}",
|
|
745
|
+
COMPUTED_FIELD_SETTABLE: "El campo {variable} es calculado y no puede establecerse directamente",
|
|
746
|
+
COMPUTED_FIELD_DANGLING_LINK: "El campo calculado {variable} referencia una fila inexistente en la tabla {variable}",
|
|
747
|
+
COMPUTED_FIELD_ARITHMETIC: "Falló la evaluación del campo calculado {variable} ({variable})",
|
|
711
748
|
},
|
|
712
749
|
};
|
|
713
750
|
/**
|
|
@@ -784,6 +821,23 @@ export const validateSchema = (schema, language = "en") => {
|
|
|
784
821
|
validateName(field.key, language);
|
|
785
822
|
if (field.table)
|
|
786
823
|
validateName(field.table, language);
|
|
824
|
+
if (typeof field.computed !== "undefined") {
|
|
825
|
+
const computed = field.computed;
|
|
826
|
+
const isValidForm = typeof computed === "string"
|
|
827
|
+
? computed.length > 0 && computed.length <= COMPUTED_EXPR_MAX_LENGTH
|
|
828
|
+
: typeof computed === "object" &&
|
|
829
|
+
computed !== null &&
|
|
830
|
+
typeof computed.expr === "string" &&
|
|
831
|
+
typeof computed.ast === "object" &&
|
|
832
|
+
computed.expr.length > 0 &&
|
|
833
|
+
computed.expr.length <= COMPUTED_EXPR_MAX_LENGTH;
|
|
834
|
+
if (!isValidForm)
|
|
835
|
+
throw createError(language, "COMPUTED_FIELD_SYNTAX", field.key);
|
|
836
|
+
if (field.required !== undefined ||
|
|
837
|
+
field.unique !== undefined ||
|
|
838
|
+
field.regex !== undefined)
|
|
839
|
+
throw createError(language, "COMPUTED_FIELD_CONFLICT", field.key);
|
|
840
|
+
}
|
|
787
841
|
if (field.children && isArrayOfObjects(field.children))
|
|
788
842
|
validateSchema(field.children, language);
|
|
789
843
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inibase",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Karim Amahtil",
|
|
@@ -87,10 +87,12 @@
|
|
|
87
87
|
"build": "tsc",
|
|
88
88
|
"benchmark": "./benchmark/run.js",
|
|
89
89
|
"benchmark:durability": "tsx ./benchmark/durability.ts",
|
|
90
|
-
"
|
|
90
|
+
"benchmark:computed": "tsx ./benchmark/computed.ts",
|
|
91
|
+
"test": "tsx ./tests/inibase.test.ts && tsx ./tests/inibase.advanced.test.ts && tsx ./tests/transaction.test.ts && tsx ./tests/durability.test.ts && tsx ./tests/expression.test.ts && tsx ./tests/utils.test.ts",
|
|
91
92
|
"test:durability": "tsx ./tests/durability.test.ts",
|
|
92
93
|
"test:transaction": "tsx ./tests/transaction.test.ts",
|
|
93
94
|
"test:utils": "tsx ./tests/utils.test.ts",
|
|
95
|
+
"test:expression": "tsx ./tests/expression.test.ts",
|
|
94
96
|
"test:advanced": "tsx ./tests/inibase.advanced.test.ts"
|
|
95
97
|
}
|
|
96
98
|
}
|