@xuda.io/xuda-studio-doc-utils 1.0.0

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 (2) hide show
  1. package/index.mjs +110 -0
  2. package/package.json +8 -0
package/index.mjs ADDED
@@ -0,0 +1,110 @@
1
+ const new_node_id = (type, app_id) => {
2
+ const abbreviate = (word) => {
3
+ if (word.length <= 3) {
4
+ return word;
5
+ }
6
+
7
+ // Remove vowels except the first letter
8
+ let abbreviation = word[0];
9
+ const vowels = 'aeiou';
10
+
11
+ for (let i = 1; i < word.length && abbreviation.length < 3; i++) {
12
+ if (!vowels.includes(word[i].toLowerCase())) {
13
+ abbreviation += word[i];
14
+ }
15
+ }
16
+
17
+ // If the abbreviation is still less than 3 letters, pad it with the remaining letters
18
+ if (abbreviation.length < 3) {
19
+ abbreviation = word.substring(0, 3);
20
+ }
21
+
22
+ return abbreviation;
23
+ };
24
+
25
+ var last12uuid = crypto.randomUUID().split('-')[4];
26
+
27
+ if (type) {
28
+ var menuAbbreviated = abbreviate(type.replaceAll('_', ''));
29
+ return `${app_id.substr(app_id.length - 3)}_${menuAbbreviated}_${last12uuid}`;
30
+ }
31
+
32
+ return app_id.substr(app_id.length - 3) + '_' + last12uuid;
33
+ };
34
+
35
+ export const createDoc = function ({ _id, uid, checkedInUserName, app_id, parentId, properties, studio_meta = {}, minimal = false } = {}) {
36
+ if (!_id) {
37
+ _id = new_node_id(properties.menuType, app_id);
38
+ }
39
+ const t = Date.now();
40
+ var doc = {
41
+ _id,
42
+ stat: 3,
43
+ app_id,
44
+ docType: 'studio',
45
+ docDate: t,
46
+ ts: t,
47
+ order_ts: t,
48
+ studio_meta: {
49
+ ...{
50
+ created: t,
51
+ createdByUid: uid,
52
+ checkedInUserId: uid,
53
+ checkedInUserName,
54
+ parentId: parentId || (properties.menuType === 'globals' ? 'globals' : properties.menuType === 'table' ? 'database' : properties.menuType === 'route' ? 'routes' : 'programs'),
55
+ },
56
+ ...studio_meta,
57
+ },
58
+ properties: properties || {},
59
+ };
60
+
61
+ if (minimal) return doc;
62
+
63
+ if (properties.menuType) {
64
+ switch (properties.menuType) {
65
+ case 'table':
66
+ if (!doc.tableIndexes) doc.tableIndexes = [];
67
+ if (!doc.tableFields) doc.tableFields = [];
68
+ break;
69
+
70
+ case 'alert':
71
+ if (!doc.alertData) doc.alertData = {};
72
+ break;
73
+
74
+ case 'javascript':
75
+ if (!doc.scriptData) doc.scriptData = {};
76
+ break;
77
+
78
+ case 'ai_agent':
79
+ if (!doc.agentConfig) doc.agentConfig = {};
80
+ break;
81
+
82
+ case 'folder':
83
+ break;
84
+
85
+ case 'route':
86
+ if (!doc.routeMenu) doc.routeMenu = {};
87
+ break;
88
+ case 'api':
89
+ if (!doc.scriptData) doc.scriptData = {};
90
+
91
+ case 'component':
92
+ if (!doc.progUi) doc.progUi = [{ id: 'root', type: 'element', tagName: doc?.properties?.renderType !== 'form' ? 'xu-multi-view' : 'xu-single-view', attributes: {}, children: [] }];
93
+
94
+ default:
95
+ //get_data, set_data, batch
96
+ if (!doc.progDataSource)
97
+ doc.progDataSource = {
98
+ dataSourceType: '',
99
+ };
100
+ if (!doc.progFields) doc.progFields = [];
101
+ if (!doc.progEvents) doc.progEvents = [];
102
+
103
+ break;
104
+ }
105
+ }
106
+
107
+ return doc;
108
+ };
109
+
110
+ export const valid_menuType = ['globals', 'table', 'get_data', 'set_data', 'batch', 'alert', 'javascript', 'folder', 'route', 'api', 'component', 'ai_agent'];
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@xuda.io/xuda-studio-doc-utils",
3
+ "version": "1.0.0",
4
+ "main": "index.mjs",
5
+ "type": "module",
6
+ "description": "Auto-generated build for xuda-studio-doc-utils.mjs",
7
+ "author": "Auto Publisher"
8
+ }