-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsourcemap.js
163 lines (125 loc) · 4.24 KB
/
sourcemap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Total.js SourceMap generator
// The MIT License
// Copyright 2023 (c) Peter Širka <[email protected]>
var timeout = null;
function stringify(schema) {
if (typeof(schema) === 'string') {
if (schema[0] !== '@')
return schema;
schema = F.jsonschemas[schema.substring(1)];
}
if (!schema)
return undefined;
var builder = [];
for (let key in schema.properties) {
let name = key;
let meta = schema.properties[key];
if (schema.required && schema.required.includes(key))
name = '*' + name;
let type = '';
if (meta.type === 'array')
type = '[' + meta.items.subtype + (meta.items.maxLength ? ('(' + meta.items.maxLength + ')') : '') + ']';
else
type = (meta.subtype || meta.type) + (meta.maxLength ? ('(' + meta.maxLength + ')') : '');
builder.push(name + ':' + type);
}
return builder.join(',');
}
exports.create = function() {
var actions = [];
var routes = [];
var items = [];
for (let key in F.actions) {
let action = F.actions[key];
let permissions = action.permissions instanceof Array ? action.permissions.join(',') : action.permissions;
items.push({ action: key, name: action.name, summary: action.summary, params: stringify(action.params), input: stringify(action.input), output: stringify(action.output), query: stringify(action.query), permissions: permissions, owner: action.$owner });
actions.push({ name: key, params: stringify(action.params), input: stringify(action.input), output: stringify(action.output), query: stringify(action.query), user: action.user, permissions: permissions, public: action.public, publish: action.publish, owner: action.$owner });
}
for (let route of F.routes.routes) {
let m = {};
m.method = route.method;
m.url = route.url2;
m.auth = route.auth;
if (route.params && route.params.length) {
m.params = [];
for (let param of route.params)
m.params.push(param.name + ':' + param.type);
m.params = m.params.join(',');
}
if (route.timeout)
m.timeout = route.timeout;
if (route.flags && route.flags.upload) {
m.upload = true;
m.limit = route.size;
}
if (route.api) {
for (let key in route.api) {
let tmp = CLONE(m);
let api = route.api[key];
tmp.id = key;
tmp.method = 'API';
tmp.auth = api.auth;
tmp.params = undefined;
let name = (api.actions.split(',')[0] || '').replaceAll('(response)', '').trim();
if (name) {
let action = F.actions[name];
if (action) {
tmp.input = action.input;
tmp.name = action.name;
tmp.summary = action.summary;
tmp.public = action.public;
if (tmp.input && tmp.input[0] === '@')
tmp.input = stringify(F.jsonschemas[tmp.input.substring(1)]);
tmp.query = action.query;
if (tmp.query && tmp.query[0] === '@')
tmp.query = stringify(F.jsonschemas[tmp.query.substring(1)]);
if (api.params && api.params.length) {
m.params = [];
for (let param of api.params)
m.params.push(param.name + ':' + (param.type || 'string'));
tmp.params = m.params.join(',');
}
} else
tmp.error = 'Action not found';
} else
tmp.error = 'Action not found';
routes.push(tmp);
}
continue;
}
routes.push(m);
}
for (let route of F.routes.websockets) {
let m = {};
m.method = 'SOCKET';
m.url = route.url2;
m.auth = route.auth;
if (route.params && route.params.length) {
m.params = [];
for (let param of route.params)
m.params.push(param.name + ':' + param.type);
m.params = m.params.join(',');
}
routes.push(m);
}
var output = {};
output.routes = routes;
output.plugins = [];
output.actions = actions;
for (let key in F.plugins) {
let plugin = F.plugins[key];
let permissions = [];
if (plugin.permissions instanceof Array) {
for (let permission of plugin.permissions)
permissions.push(permission.id || permission);
}
output.plugins.push({ id: key, name: plugin.name, permissions: permissions.join(',') });
}
return output;
};
exports.refresh = function() {
if (!F.isLoaded || !F.config.$sourcemap || F.id)
return;
timeout && clearTimeout(timeout);
timeout = setTimeout(() => F.Fs.writeFile(process.mainModule.filename + '.map', JSON.stringify(F.sourcemap(), (key, value) => value == '' || value == null ? undefined : value, '\t'), NOOP), 1000);
};