data-primals-engine 1.5.0 → 1.5.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.
Files changed (63) hide show
  1. package/README.md +37 -0
  2. package/client/src/AddWidgetTypeModal.jsx +47 -43
  3. package/client/src/App.jsx +2 -6
  4. package/client/src/App.scss +13 -1
  5. package/client/src/AssistantChat.jsx +363 -323
  6. package/client/src/AssistantChat.scss +27 -10
  7. package/client/src/Dashboard.jsx +480 -396
  8. package/client/src/Dashboard.scss +1 -1
  9. package/client/src/DashboardHtmlViewItem.jsx +147 -0
  10. package/client/src/DashboardView.jsx +654 -569
  11. package/client/src/DataEditor.jsx +10 -3
  12. package/client/src/DataLayout.jsx +807 -755
  13. package/client/src/DataLayout.scss +14 -0
  14. package/client/src/DataTable.jsx +39 -75
  15. package/client/src/Dialog.scss +1 -1
  16. package/client/src/Field.jsx +2057 -1825
  17. package/client/src/FlexViewCard.jsx +44 -0
  18. package/client/src/HistoryDialog.jsx +69 -14
  19. package/client/src/HtmlViewBuilderModal.jsx +91 -0
  20. package/client/src/HtmlViewBuilderModal.scss +18 -0
  21. package/client/src/HtmlViewCard.jsx +44 -0
  22. package/client/src/HtmlViewCard.scss +35 -0
  23. package/client/src/KanbanCard.jsx +1 -2
  24. package/client/src/ModelCreator.jsx +5 -4
  25. package/client/src/ModelCreatorField.jsx +51 -4
  26. package/client/src/ModelList.jsx +280 -236
  27. package/client/src/Notification.jsx +136 -136
  28. package/client/src/Notification.scss +0 -18
  29. package/client/src/Pagination.jsx +5 -3
  30. package/client/src/RelationField.jsx +354 -258
  31. package/client/src/RelationSelectorWidget.jsx +173 -0
  32. package/client/src/contexts/ModelContext.jsx +10 -1
  33. package/client/src/contexts/UIContext.jsx +72 -63
  34. package/client/src/filter.js +263 -212
  35. package/client/src/hooks/useValidation.js +75 -0
  36. package/client/src/translations.js +24 -24
  37. package/package.json +7 -6
  38. package/src/constants.js +1 -1
  39. package/src/core.js +8 -1
  40. package/src/defaultModels.js +1596 -1544
  41. package/src/engine.js +85 -43
  42. package/src/events.js +137 -113
  43. package/src/i18n.js +710 -10
  44. package/src/index.js +3 -0
  45. package/src/modules/assistant/assistant.js +253 -134
  46. package/src/modules/assistant/constants.js +2 -1
  47. package/src/modules/bucket.js +2 -1
  48. package/src/modules/data/data.core.js +118 -92
  49. package/src/modules/data/data.history.js +555 -492
  50. package/src/modules/data/data.js +3 -53
  51. package/src/modules/data/data.operations.js +3381 -3231
  52. package/src/modules/data/data.relations.js +686 -686
  53. package/src/modules/data/data.routes.js +1879 -1821
  54. package/src/modules/data/data.validation.js +81 -2
  55. package/src/modules/file.js +247 -238
  56. package/src/modules/user.js +1 -0
  57. package/src/modules/workflow.js +2 -2
  58. package/src/openai.jobs.js +3 -2
  59. package/src/packs.js +5482 -5478
  60. package/src/sso.js +2 -2
  61. package/src/workers/import-export-worker.js +1 -1
  62. package/test/data.history.integration.test.js +264 -192
  63. package/test/data.integration.test.js +149 -3
@@ -1,93 +1,119 @@
1
- import NodeCache from "node-cache";
2
- import path from "node:path";
3
- import {Worker} from 'worker_threads';
4
- import {fileURLToPath} from "node:url";
5
- export const modelsCache = new NodeCache( { stdTTL: 100, checkperiod: 120 } );
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- export const mongoDBWhitelist = [
11
- "$$NOW", "$in", "$eq", "$gt", "$gte", "$in", "$lt", "$lte", "$ne", "$nin", "$type", "$size",
12
- "$and", "$not", "$nor", "$or", "$regexMatch", "$find", "$elemMatch", "$filter", "$toString", "$toObjectId",
13
- "$concat",
14
- '$add', '$subtract', '$multiply', '$divide', '$mod', '$pow', "$sqrt",
15
- "$rand",
16
- "$abs", '$sin', '$cos', '$tan', '$asin', '$acos', '$atan',
17
- "$toDate", "$toBool", "$toString", "$toInt", "$toDouble",
18
- "$dateDiff", "$dateSubtract", "$dateAdd", "$dateToString",
19
- '$year', '$month', '$week', '$dayOfMonth', '$dayOfWeek', '$dayOfYear', '$hour', '$minute', '$second', '$millisecond',
20
- '$geoNear', '$regex', '$text', '$nearSphere','$geoWithin','$geoIntersects'
21
- ];
22
- export let importJobs = {};
23
-
24
-
25
- /**
26
- * Exécute une tâche d'import/export (parsing, stringify) dans un worker thread.
27
- * @param {('parse-json'|'parse-csv'|'stringify-json')} action - L'action à effectuer.
28
- * @param {object} payload - Les données nécessaires pour l'action.
29
- * @returns {Promise<any>} - Une promesse qui se résout avec les données traitées.
30
- */
31
- export function runImportExportWorker(action, payload) {
32
- return new Promise((resolve, reject) => {
33
- const workerPath = path.resolve(process.cwd(), './src/workers/import-export-worker.js');
34
- const worker = new Worker(workerPath);
35
-
36
- worker.postMessage({ action, payload });
37
-
38
- worker.on('message', (result) => {
39
- if (result.success) {
40
- resolve(result.data);
41
- } else {
42
- // Correction : On s'assure de toujours passer une chaîne de caractères à new Error()
43
- const errorMessage = result.error || `Import/Export Worker failed with an unknown error. Action: ${action}.`;
44
- reject(new Error(errorMessage));
45
- }
46
- worker.terminate();
47
- });
48
-
49
- worker.on('error', (err) => {
50
- reject(err);
51
- worker.terminate();
52
- });
53
-
54
- worker.on('exit', (code) => {
55
- if (code !== 0) {
56
- reject(new Error(`Import/Export Worker stopped with exit code ${code}`));
57
- }
58
- });
59
- });
60
- }
61
- /** Exécute une tâche de cryptographie dans un worker thread.
62
- * @param {('encrypt'|'decrypt'|'hash')} action - L'action à effectuer.
63
- * @param {object} payload - Les données nécessaires pour l'action.
64
- * @returns {Promise<any>} - Une promesse qui se résout avec le résultat (si pertinent).
65
- */
66
- export function runCryptoWorkerTask(action, payload) {
67
- return new Promise((resolve, reject) => {
68
- const workerPath = path.resolve(__dirname, '../../workers/crypto-worker.js');
69
- const worker = new Worker(workerPath);
70
-
71
- worker.postMessage({ action, payload });
72
-
73
- worker.on('message', (result) => {
74
- if (result.success) {
75
- resolve(result.data); // Résout avec les données (ex: le hash) ou undefined si pas de retour
76
- } else {
77
- reject(new Error(result.error));
78
- }
79
- worker.terminate();
80
- });
81
-
82
- worker.on('error', (err) => {
83
- reject(err);
84
- worker.terminate();
85
- });
86
-
87
- worker.on('exit', (code) => {
88
- if (code !== 0) {
89
- reject(new Error(`Crypto Worker stopped with exit code ${code}`));
90
- }
91
- });
92
- });
1
+ import NodeCache from "node-cache";
2
+ import path from "node:path";
3
+ import {Worker} from 'worker_threads';
4
+ import {fileURLToPath} from "node:url";
5
+ export const modelsCache = new NodeCache( { stdTTL: 100, checkperiod: 120 } );
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ /**
11
+ * Helper to escape characters for regex.
12
+ * @param {string} str The string to escape.
13
+ * @returns {string} The escaped string.
14
+ */
15
+ function escapeRegex(str) {
16
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
17
+ }
18
+
19
+ /**
20
+ * Generates a regular expression from a mask pattern and replacement rules.
21
+ * @param {string} mask - The mask pattern, e.g., '+0 (___) ___-__-__'.
22
+ * @param {object} replacement - An object mapping placeholder characters to regex patterns, e.g., { "_": "\\d" }.
23
+ * @returns {string|null} - A regular expression string or null if inputs are invalid.
24
+ */
25
+ export function generateRegexFromMask(mask, replacement) {
26
+ if (!mask || !replacement || typeof replacement !== 'object') return null;
27
+
28
+ let regex = '^';
29
+ for (const char of mask) {
30
+ regex += replacement[char] ? `(${replacement[char]})` : escapeRegex(char);
31
+ }
32
+ regex += '$';
33
+ return regex;
34
+ }
35
+
36
+ export const mongoDBWhitelist = [
37
+ "$$NOW", "$in", "$eq", "$gt", "$gte", "$in", "$lt", "$lte", "$ne", "$nin", "$type", "$size",
38
+ "$and", "$not", "$nor", "$or", "$regexMatch", "$find", "$elemMatch", "$filter", "$toString", "$toObjectId",
39
+ "$concat",
40
+ '$add', '$subtract', '$multiply', '$divide', '$mod', '$pow', "$sqrt",
41
+ "$rand",
42
+ "$abs", '$sin', '$cos', '$tan', '$asin', '$acos', '$atan',
43
+ "$toDate", "$toBool", "$toString", "$toInt", "$toDouble",
44
+ "$dateDiff", "$dateSubtract", "$dateAdd", "$dateToString",
45
+ '$year', '$month', '$week', '$dayOfMonth', '$dayOfWeek', '$dayOfYear', '$hour', '$minute', '$second', '$millisecond',
46
+ '$geoNear', '$regex', '$text', '$nearSphere','$geoWithin','$geoIntersects'
47
+ ];
48
+ export let importJobs = {};
49
+
50
+
51
+ /**
52
+ * Exécute une tâche d'import/export (parsing, stringify) dans un worker thread.
53
+ * @param {('parse-json'|'parse-csv'|'stringify-json')} action - L'action à effectuer.
54
+ * @param {object} payload - Les données nécessaires pour l'action.
55
+ * @returns {Promise<any>} - Une promesse qui se résout avec les données traitées.
56
+ */
57
+ export function runImportExportWorker(action, payload) {
58
+ return new Promise((resolve, reject) => {
59
+ const workerPath = path.resolve(process.cwd(), './src/workers/import-export-worker.js');
60
+ const worker = new Worker(workerPath);
61
+
62
+ worker.postMessage({ action, payload });
63
+
64
+ worker.on('message', (result) => {
65
+ if (result.success) {
66
+ resolve(result.data);
67
+ } else {
68
+ // Correction : On s'assure de toujours passer une chaîne de caractères à new Error()
69
+ const errorMessage = result.error || `Import/Export Worker failed with an unknown error. Action: ${action}.`;
70
+ reject(new Error(errorMessage));
71
+ }
72
+ worker.terminate();
73
+ });
74
+
75
+ worker.on('error', (err) => {
76
+ reject(err);
77
+ worker.terminate();
78
+ });
79
+
80
+ worker.on('exit', (code) => {
81
+ if (code !== 0) {
82
+ reject(new Error(`Import/Export Worker stopped with exit code ${code}`));
83
+ }
84
+ });
85
+ });
86
+ }
87
+ /** Exécute une tâche de cryptographie dans un worker thread.
88
+ * @param {('encrypt'|'decrypt'|'hash')} action - L'action à effectuer.
89
+ * @param {object} payload - Les données nécessaires pour l'action.
90
+ * @returns {Promise<any>} - Une promesse qui se résout avec le résultat (si pertinent).
91
+ */
92
+ export function runCryptoWorkerTask(action, payload) {
93
+ return new Promise((resolve, reject) => {
94
+ const workerPath = path.resolve(__dirname, '../../workers/crypto-worker.js');
95
+ const worker = new Worker(workerPath);
96
+
97
+ worker.postMessage({ action, payload });
98
+
99
+ worker.on('message', (result) => {
100
+ if (result.success) {
101
+ resolve(result.data); // Résout avec les données (ex: le hash) ou undefined si pas de retour
102
+ } else {
103
+ reject(new Error(result.error));
104
+ }
105
+ worker.terminate();
106
+ });
107
+
108
+ worker.on('error', (err) => {
109
+ reject(err);
110
+ worker.terminate();
111
+ });
112
+
113
+ worker.on('exit', (code) => {
114
+ if (code !== 0) {
115
+ reject(new Error(`Crypto Worker stopped with exit code ${code}`));
116
+ }
117
+ });
118
+ });
93
119
  }