divhunt 2.0.14 → 2.0.16
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/addons/core/servers/back/http/item/functions/start.js +21 -4
- package/addons/modules/variables/{addon.js → core/addon.js} +1 -2
- package/addons/modules/variables/core/functions/process.js +46 -0
- package/addons/modules/variables/core/item/catch/add.js +6 -0
- package/addons/modules/variables/core/load.js +13 -0
- package/addons/modules/variables/front/events/compile.js +12 -0
- package/addons/render/assets/back/functions/import.js +2 -1
- package/lib/browser.js +2 -1
- package/lib/load.js +3 -1
- package/lib/src/divhunt.js +2 -0
- package/lib/src/mixins/data.js +6 -1
- package/package.json +2 -2
- package/test/front/test.js +2 -0
- package/test.js +4 -1
- package/addons/modules/variables/functions/filter.js +0 -24
- package/addons/modules/variables/functions/process.js +0 -52
- package/addons/modules/variables/item/catch/add.js +0 -13
- package/addons/modules/variables/load.js +0 -8
|
@@ -22,15 +22,16 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
22
22
|
return {
|
|
23
23
|
id: divhunt.GenerateUID(),
|
|
24
24
|
request,
|
|
25
|
+
response,
|
|
26
|
+
error: null,
|
|
27
|
+
streaming: false,
|
|
28
|
+
prevent: false,
|
|
25
29
|
data: await serversHTTP.Fn('extract.data', request),
|
|
26
30
|
url: new URL(request.url, `http://${request.headers.host}`),
|
|
27
31
|
user: this.methods.user(request),
|
|
28
32
|
time: performance.now(),
|
|
29
|
-
error: null,
|
|
30
|
-
response,
|
|
31
|
-
streaming: false,
|
|
32
33
|
types: this.methods.types,
|
|
33
|
-
|
|
34
|
+
context: {},
|
|
34
35
|
respond: {
|
|
35
36
|
type: 'JSON',
|
|
36
37
|
data: null,
|
|
@@ -102,6 +103,9 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
102
103
|
{
|
|
103
104
|
const http = await this.methods.createHttpObject(request, response);
|
|
104
105
|
|
|
106
|
+
await divhunt.Middleware('servers.http.request', http);
|
|
107
|
+
divhunt.Emit('servers.http.request', http);
|
|
108
|
+
|
|
105
109
|
try
|
|
106
110
|
{
|
|
107
111
|
if(item.Get('onRequest'))
|
|
@@ -109,6 +113,9 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
109
113
|
await Promise.resolve(item.Get('onRequest')(http));
|
|
110
114
|
}
|
|
111
115
|
|
|
116
|
+
await divhunt.Middleware('servers.http.respond', http);
|
|
117
|
+
divhunt.Emit('servers.http.respond', http);
|
|
118
|
+
|
|
112
119
|
this.methods.respond(http, response);
|
|
113
120
|
}
|
|
114
121
|
catch(error)
|
|
@@ -119,10 +126,19 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
119
126
|
http.errorCode = code;
|
|
120
127
|
http.errorContext = error.context || {};
|
|
121
128
|
|
|
129
|
+
await divhunt.Middleware('servers.http.error', http);
|
|
130
|
+
divhunt.Emit('servers.http.error', http);
|
|
131
|
+
|
|
122
132
|
item.Get('onError') && item.Get('onError')(http.error);
|
|
123
133
|
|
|
134
|
+
await divhunt.Middleware('servers.http.respond', http);
|
|
135
|
+
divhunt.Emit('servers.http.respond', http);
|
|
136
|
+
|
|
124
137
|
this.methods.respond(http, response);
|
|
125
138
|
}
|
|
139
|
+
|
|
140
|
+
await divhunt.Middleware('servers.http.complete', http);
|
|
141
|
+
divhunt.Emit('servers.http.complete', http);
|
|
126
142
|
});
|
|
127
143
|
|
|
128
144
|
httpServer.on('error', (error) =>
|
|
@@ -133,6 +149,7 @@ serversHTTP.Fn('item.start', function(item)
|
|
|
133
149
|
httpServer.listen(item.Get('port'), () =>
|
|
134
150
|
{
|
|
135
151
|
item.Set('instance', httpServer);
|
|
152
|
+
divhunt.Emit('servers.http.start', httpServer);
|
|
136
153
|
item.Get('onStart') && item.Get('onStart')(httpServer);
|
|
137
154
|
});
|
|
138
155
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import divhunt from '#
|
|
1
|
+
import divhunt from '#framework/load.js';
|
|
2
2
|
|
|
3
3
|
const variables = divhunt.Addon('variables', (addon) =>
|
|
4
4
|
{
|
|
5
5
|
addon.Field('id', ['string']);
|
|
6
6
|
addon.Field('value', ['any']);
|
|
7
7
|
addon.Field('type', ['string']);
|
|
8
|
-
addon.Field('key', ['string', null]);
|
|
9
8
|
addon.Field('group', ['string', null]);
|
|
10
9
|
});
|
|
11
10
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import divhunt from '#framework/load.js';
|
|
2
|
+
import variables from '#variables/core/addon.js';
|
|
3
|
+
|
|
4
|
+
variables.Fn('process', function(string)
|
|
5
|
+
{
|
|
6
|
+
if(typeof string !== 'string')
|
|
7
|
+
{
|
|
8
|
+
return string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const safe = divhunt.environment === 'back';
|
|
12
|
+
const data = {};
|
|
13
|
+
|
|
14
|
+
for(const id in this.items.data)
|
|
15
|
+
{
|
|
16
|
+
data[id] = this.items.data[id].Get('value');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if(!string.includes('${'))
|
|
20
|
+
{
|
|
21
|
+
const result = divhunt.Function(string, data, safe);
|
|
22
|
+
|
|
23
|
+
return result !== undefined ? result : string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const single = string.match(/^\$\{([^}]+)\}$/);
|
|
27
|
+
|
|
28
|
+
if(single)
|
|
29
|
+
{
|
|
30
|
+
const result = divhunt.Function(single[1], data, safe);
|
|
31
|
+
|
|
32
|
+
return result !== undefined ? result : string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return string.replace(/\$\{([^}]+)\}/g, (match, expression) =>
|
|
36
|
+
{
|
|
37
|
+
const result = divhunt.Function(expression, data, safe);
|
|
38
|
+
|
|
39
|
+
if(result === undefined || (typeof result === 'object' && result !== null))
|
|
40
|
+
{
|
|
41
|
+
return match;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import divhunt from '#framework/load.js';
|
|
2
|
+
import variables from '#variables/core/addon.js';
|
|
3
|
+
|
|
4
|
+
import '#variables/core/item/catch/add.js';
|
|
5
|
+
|
|
6
|
+
import '#variables/core/functions/process.js';
|
|
7
|
+
|
|
8
|
+
divhunt.$dh.var = function(string)
|
|
9
|
+
{
|
|
10
|
+
return variables.Fn('process', string);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default variables;
|
|
@@ -8,9 +8,10 @@ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', '..',
|
|
|
8
8
|
const map =
|
|
9
9
|
{
|
|
10
10
|
framework: { js: 'lib', ignore: ['lib/load.js'] },
|
|
11
|
-
commands: { js: 'addons/core/commands',
|
|
11
|
+
commands: { js: 'addons/core/commands', ignore: ['addons/core/commands/back'] },
|
|
12
12
|
database: { js: 'addons/core/database/front' },
|
|
13
13
|
actions: { js: 'addons/modules/actions/front' },
|
|
14
|
+
variables: { js: 'addons/modules/variables' },
|
|
14
15
|
bugs: { js: 'addons/modules/bugs/front' },
|
|
15
16
|
events: { js: 'addons/modules/events/front' },
|
|
16
17
|
schedules: { js: 'addons/modules/schedules/front' },
|
package/lib/browser.js
CHANGED
package/lib/load.js
CHANGED
package/lib/src/divhunt.js
CHANGED
package/lib/src/mixins/data.js
CHANGED
|
@@ -119,6 +119,11 @@ const DivhuntData =
|
|
|
119
119
|
{
|
|
120
120
|
return type.split('|').map(t => t.trim().toLowerCase()).some(type =>
|
|
121
121
|
{
|
|
122
|
+
if (type === 'any')
|
|
123
|
+
{
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
122
127
|
if (type === 'array')
|
|
123
128
|
{
|
|
124
129
|
return Array.isArray(value);
|
|
@@ -249,7 +254,7 @@ const DivhuntData =
|
|
|
249
254
|
|
|
250
255
|
parsed.type.split('|').forEach((type) =>
|
|
251
256
|
{
|
|
252
|
-
if(!['number', 'string', 'boolean', 'object', 'array', 'function', 'binary'].includes(type))
|
|
257
|
+
if(!['number', 'string', 'boolean', 'object', 'array', 'function', 'binary', 'any'].includes(type))
|
|
253
258
|
{
|
|
254
259
|
throw new Error('Invalid config type. Expected number, string, boolean, object, array, function or binary.');
|
|
255
260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "divhunt",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Full-stack isomorphic JavaScript framework built from scratch. One addon abstraction powers databases, servers, commands, pages, directives, queues, and more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/load.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./html": "./addons/render/html/load.js",
|
|
21
21
|
"./tags": "./addons/render/tags/load.js",
|
|
22
22
|
"./sources": "./addons/modules/sources/back/load.js",
|
|
23
|
-
"./variables": "./addons/modules/variables/load.js"
|
|
23
|
+
"./variables": "./addons/modules/variables/core/load.js"
|
|
24
24
|
},
|
|
25
25
|
"imports": {
|
|
26
26
|
"#framework/*": "./lib/*",
|
package/test/front/test.js
CHANGED
package/test.js
CHANGED
|
@@ -7,8 +7,9 @@ import assets from './addons/render/assets/back/load.js';
|
|
|
7
7
|
import commands from './addons/core/commands/core/load.js';
|
|
8
8
|
import pages from './addons/render/pages/core/load.js';
|
|
9
9
|
import html from './addons/render/html/load.js';
|
|
10
|
+
import variables from './addons/modules/variables/core/load.js';
|
|
10
11
|
|
|
11
|
-
assets.Fn('import', ['framework', 'directives', 'commands', 'pages']);
|
|
12
|
+
assets.Fn('import', ['framework', 'variables', 'directives', 'commands', 'pages']);
|
|
12
13
|
assets.Item({ type: 'js', order: 10, path: resolve(root, 'test/front') });
|
|
13
14
|
assets.Item({ type: 'css', order: 10, path: resolve(root, 'test/front') });
|
|
14
15
|
|
|
@@ -24,6 +25,8 @@ commands.Item({
|
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
27
|
|
|
28
|
+
console.log($dh.var('test'));
|
|
29
|
+
|
|
27
30
|
commands.Item({
|
|
28
31
|
id: 'test',
|
|
29
32
|
exposed: true,
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import variables from '../addon.js';
|
|
2
|
-
|
|
3
|
-
variables.Fn('filter', function(group = null)
|
|
4
|
-
{
|
|
5
|
-
const result = [];
|
|
6
|
-
|
|
7
|
-
for(const id in this.items.data)
|
|
8
|
-
{
|
|
9
|
-
const item = this.items.data[id];
|
|
10
|
-
|
|
11
|
-
if(group === null || item.Get('group') === group)
|
|
12
|
-
{
|
|
13
|
-
result.push({
|
|
14
|
-
id: item.Get('id'),
|
|
15
|
-
value: item.Get('value'),
|
|
16
|
-
type: item.Get('type'),
|
|
17
|
-
key: item.Get('key'),
|
|
18
|
-
group: item.Get('group')
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import divhunt from '#divhunt';
|
|
2
|
-
import variables from '../addon.js';
|
|
3
|
-
|
|
4
|
-
variables.Fn('process', function(string)
|
|
5
|
-
{
|
|
6
|
-
if(typeof string !== 'string')
|
|
7
|
-
{
|
|
8
|
-
return string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return string.replace(/\$\{([^}]+)\}/g, (match, expr) =>
|
|
12
|
-
{
|
|
13
|
-
const parts = expr.trim().split('.');
|
|
14
|
-
const id = parts[0];
|
|
15
|
-
const key = parts.slice(1).join('.');
|
|
16
|
-
|
|
17
|
-
const item = this.ItemGet(id);
|
|
18
|
-
|
|
19
|
-
if(!item)
|
|
20
|
-
{
|
|
21
|
-
try
|
|
22
|
-
{
|
|
23
|
-
return divhunt.Function(`return ${expr}`)();
|
|
24
|
-
}
|
|
25
|
-
catch
|
|
26
|
-
{
|
|
27
|
-
return match;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let value = item.Get('value');
|
|
32
|
-
|
|
33
|
-
if(key && typeof value === 'object' && value !== null)
|
|
34
|
-
{
|
|
35
|
-
const keys = key.split('.');
|
|
36
|
-
|
|
37
|
-
for(const k of keys)
|
|
38
|
-
{
|
|
39
|
-
if(value && typeof value === 'object' && k in value)
|
|
40
|
-
{
|
|
41
|
-
value = value[k];
|
|
42
|
-
}
|
|
43
|
-
else
|
|
44
|
-
{
|
|
45
|
-
return match;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return value;
|
|
51
|
-
});
|
|
52
|
-
});
|