mushroom-cli 1.2.0-alpha.10 → 1.2.0-alpha.12

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 (43) hide show
  1. package/README.md +233 -211
  2. package/dist/check-update.js +5 -0
  3. package/dist/common.js +260 -0
  4. package/dist/config.js +394 -0
  5. package/{docs → dist/docs}/doc-mt.js +471 -523
  6. package/dist/docs/docs.v2.js +1758 -0
  7. package/{docs → dist/docs}/mt-dom-1.0.js +1025 -1268
  8. package/{docs → dist/docs}/mt.extension.js +142 -174
  9. package/dist/gen/gen-api-docs-v1.js +106 -0
  10. package/dist/gen/gen-api-docs.js +292 -0
  11. package/{gen → dist/gen}/gen-csharp.js +1265 -1399
  12. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  13. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  14. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  15. package/{gen → dist/gen}/gen-ts-driver.js +427 -471
  16. package/{gen.js → dist/gen.js} +109 -124
  17. package/{help.js → dist/help.js} +53 -55
  18. package/dist/init/init-json.js +91 -0
  19. package/dist/init/init-netcore.js +30 -0
  20. package/dist/init.js +23 -0
  21. package/dist/master-file/master-file.js +185 -0
  22. package/dist/merge.js +70 -0
  23. package/dist/mr.js +75 -0
  24. package/dist/types.js +1 -0
  25. package/dist/update/tsCode.js +82 -0
  26. package/dist/update.js +20 -0
  27. package/package.json +54 -29
  28. package/check-update.js +0 -9
  29. package/common.js +0 -273
  30. package/config.js +0 -445
  31. package/docs/docs.html +0 -5190
  32. package/docs/docs.v2.html +0 -5066
  33. package/docs/docs.v2.js +0 -1563
  34. package/gen/gen-api-docs-v1.js +0 -125
  35. package/gen/gen-api-docs.js +0 -298
  36. package/init/init-json.js +0 -106
  37. package/init/init-netcore.js +0 -32
  38. package/init.js +0 -28
  39. package/master-file/master-file.js +0 -234
  40. package/merge.js +0 -84
  41. package/mr.js +0 -82
  42. package/update/tsCode.js +0 -20
  43. package/update.js +0 -24
@@ -1,523 +1,471 @@
1
- function toCSharpName(str) {
2
- var name = str.replace(/\W/g, "_");
3
- return name.charAt(0).toUpperCase() + name.substr(1);
4
- }
5
-
6
- function getHttpMethod(actionName) {
7
- switch (actionName) {
8
- case "findMany":
9
- case "findById":
10
- return "GET";
11
- case "createOne":
12
- case "createMany":
13
- return "POST";
14
- case "updateOne":
15
- case "updateMany":
16
- return "PUT";
17
- case "updatePartially":
18
- return "PATCH";
19
- case "deleteOne":
20
- case "deleteMany":
21
- return "DELETE";
22
- default:
23
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
24
- return actionName.substr("_raw_http_method_".length);
25
- return "UNKNOWN(" + actionName + ")";
26
- }
27
- }
28
-
29
- function getPanelClass(actionName) {
30
- switch (actionName) {
31
- case "findMany":
32
- case "findById":
33
- return "panel panel-primary";
34
- case "createOne":
35
- case "createMany":
36
- return "panel panel-info";
37
- case "updateOne":
38
- case "updateMany":
39
- return "panel panel-warning";
40
- case "updatePartially":
41
- return "panel panel-warning";
42
- case "deleteOne":
43
- case "deleteMany":
44
- return "panel panel-danger";
45
- default:
46
- return "panel panel-default";
47
- }
48
- }
49
-
50
- function getApiUrl(actionName, rootUrl, entityName) {
51
- switch (actionName) {
52
- case "findMany":
53
- case "createOne":
54
- case "createMany":
55
- case "updateMany":
56
- case "deleteMany":
57
- return rootUrl + entityName + "s";
58
- case "findById":
59
- case "updateOne":
60
- case "updatePartially":
61
- case "deleteOne":
62
- return rootUrl + entityName + "s/{" + entityName + "Id}";
63
- default:
64
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
65
- return rootUrl + entityName + "s/" + actionName.substr("_raw_http_method_".length);
66
- return "UNKNOWN(" + actionName + ")";
67
- }
68
- }
69
-
70
- function getApiViewUrl(rootUrl, entityName, viewName) {
71
- return rootUrl + entityName + "s/views/" + viewName;
72
- }
73
-
74
- function getDescriptionByActionName(actionName, entityName) {
75
- switch (actionName) {
76
- case "findMany":
77
- return "Lấy về danh sách các " + entityName;
78
- case "findById":
79
- return "Lấy về một " + entityName + " theo mã của nó";
80
- case "createOne":
81
- return "Tạo mới một " + entityName;
82
- case "createMany":
83
- return "Tạo mới hàng loạt các " + entityName;
84
- case "updateOne":
85
- return "Cập nhật một " + entityName;
86
- case "updateMany":
87
- return "Cập nhật hàng loạt các " + entityName;
88
- case "updatePartially":
89
- return "Cập nhật một phần dữ liệu của " + entityName;
90
- case "deleteOne":
91
- return "Xóa một " + entityName + " theo mã của nó";
92
- case "deleteMany":
93
- return "Xóa hàng loạt " + entityName;
94
- default:
95
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
96
- return "";
97
- return "UNKNOWN(" + actionName + ")";
98
- }
99
- }
100
-
101
- function getModalOutput(arrFields, fields, options) {
102
- if (!fields || !arrFields)
103
- return "";
104
-
105
- var obj = {};
106
- for (var j = 0; j < arrFields.length; j++) {
107
- if (!arrFields[j])
108
- continue;
109
- var segs = arrFields[j].split('.');
110
- var objFields = fields;
111
- var cur = obj;
112
- for (var i = 0; i < segs.length; i++) {
113
- if (segs[i] in objFields) {
114
- var field = objFields[segs[i]];
115
-
116
- if (i === segs.length - 1) {
117
- if (!(segs[i] in cur))
118
- cur[segs[i]] = JSON.parse(JSON.stringify(field));
119
- }
120
- else if (field.type === "object") {
121
- objFields = field.fields;
122
- if (!(segs[i] in cur)) {
123
- var o = { type: "object", fields: {} };
124
- cur[segs[i]] = o;
125
- cur = o.fields;
126
- } else
127
- cur = cur[segs[i]].fields;
128
- }
129
- else if (field.type === "array") {
130
- objFields = field.items.fields;
131
- if (!(segs[i] in cur)) {
132
- var a = { type: "array", items: { type: "object", fields: {}} };
133
- cur[segs[i]] = a;
134
- cur = a.items.fields;
135
- } else
136
- cur = cur[segs[i]].items.fields;
137
- }
138
- }
139
- }
140
- }
141
-
142
- return formatModal(obj, "", options)/* + JSON.stringify(obj)*/;
143
- }
144
-
145
- function formatModal(obj, strIndent, options) {
146
- if (!obj)
147
- return "";
148
-
149
- options = options || {};
150
-
151
- var result = "";
152
- var nextIndent = strIndent + " ";
153
- for (var m in obj) {
154
- if (!obj.hasOwnProperty(m))
155
- continue;
156
-
157
- var child = obj[m];
158
-
159
- var validation = !options.optionalToAll && child.validation && child.validation.required ? "required" : "optional";
160
- if (child.type === "IdRef" && child.reference) {
161
- validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
162
- }
163
-
164
- if (child.validation) {
165
- if ("validValues" in child.validation)
166
- validation += ", enum(" + encodeHtml(child.validation.validValues.join(", ")) + ")";
167
- if ("invalidValues" in child.validation)
168
- validation += ", not allow(" + encodeHtml(child.validation.invalidValues.join(", ")) + ")";
169
- if ("pattern" in child.validation)
170
- validation += ", pattern: /" + encodeHtml(child.validation.pattern) + "/";
171
- if ("length" in child.validation)
172
- validation += ", length: " + child.validation.length;
173
- if ("minLength" in child.validation)
174
- validation += ", minLength: " + child.validation.minLength;
175
- if ("maxLength" in child.validation)
176
- validation += ", maxLength: " + child.validation.maxLength;
177
- if ("min" in child.validation)
178
- validation += ", min: " + encodeHtml(child.validation.min);
179
- if ("max" in child.validation)
180
- validation += ", max: " + encodeHtml(child.validation.max);
181
- if ("gt" in child.validation)
182
- validation += ", gt: " + encodeHtml(child.validation.gt);
183
- if ("lt" in child.validation)
184
- validation += ", lt: " + encodeHtml(child.validation.lt);
185
- }
186
-
187
- if (child.type === "array" && child.items && child.items.type != "object" && child.items.validation) {
188
- validation += ", array items: " + (!options.optionalToAll && child.items.validation.required ? "required" : "optional");
189
- if ("validValues" in child.items.validation)
190
- validation += ", enum(" + encodeHtml(child.items.validation.validValues.join(", ")) + ")";
191
- if ("invalidValues" in child.items.validation)
192
- validation += ", not allow(" + encodeHtml(child.items.validation.invalidValues.join(", ")) + ")";
193
- if ("pattern" in child.items.validation)
194
- validation += ", pattern: /" + encodeHtml(child.items.validation.pattern) + "/";
195
- if ("length" in child.items.validation)
196
- validation += ", length: " + child.items.validation.length;
197
- if ("minLength" in child.items.validation)
198
- validation += ", minLength: " + child.items.validation.minLength;
199
- if ("maxLength" in child.items.validation)
200
- validation += ", maxLength: " + child.items.validation.maxLength;
201
- if ("min" in child.items.validation)
202
- validation += ", min: " + encodeHtml(child.items.validation.min);
203
- if ("max" in child.items.validation)
204
- validation += ", max: " + encodeHtml(child.items.validation.max);
205
- if ("gt" in child.items.validation)
206
- validation += ", gt: " + encodeHtml(child.items.validation.gt);
207
- if ("lt" in child.items.validation)
208
- validation += ", lt: " + encodeHtml(child.items.validation.lt);
209
- }
210
-
211
- var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
212
-
213
- if (options.mode === "modal") {
214
- if (child.type === "object")
215
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options) + ",";
216
- else if (child.type === "array") {
217
- result += `\r\n${nextIndent}"${m}": [`;
218
- if (child.items.type === "object")
219
- result += " " + comment + formatModal(child.items.fields, nextIndent, options);
220
- else if (child.items.type === "datetime")
221
- result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
222
- else if (child.items.type === "boolean")
223
- result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
224
- else if (child.items.type === "integer" || child.items.type === "long"|| child.items.type === "double")
225
- result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
226
- else
227
- result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
228
- result += `]`;
229
- }
230
- else if (child.type === "datetime")
231
- result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
232
- else if (child.type === "boolean")
233
- result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
234
- else if (child.type === "integer" || child.type === "long"|| child.type === "double")
235
- result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
236
- else
237
- result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
238
- } else if (options.mode === "modal_null") {
239
- if (child.type === "object")
240
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
241
- else if (child.type === "array") {
242
- result += `\r\n${nextIndent}"${m}": [`;
243
- if (child.items.type === "object")
244
- result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "],";
245
- else
246
- result += "], " + comment;
247
- }
248
- else
249
- result += `\r\n${nextIndent}"${m}": null, ${comment}`;
250
- } else if (options.mode === "modal_undefined") {
251
- if (child.type === "object")
252
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
253
- else if (child.type === "array") {
254
- result += `\r\n${nextIndent}"${m}": [`;
255
- if (child.items.type === "object")
256
- result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "], ";
257
- else
258
- result += "], " + comment;
259
- }
260
- else
261
- result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
262
- } else {
263
- result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
264
- if (child.type === "array")
265
- result += child.items.type === "object" ? " of object" : " of " + child.items.type;
266
- if (child.type === "object")
267
- result += " " + comment + formatModal(child.fields, strIndent + " ", options);
268
- else if (child.type === "array" && child.items.type === "object")
269
- result += " " + comment + formatModal(child.items.fields, strIndent + " ", options);
270
- else
271
- result += ", " + comment;
272
- }
273
- }
274
-
275
- if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
276
- return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
277
- }
278
-
279
- return result;
280
- }
281
-
282
- function formatHintModal(obj, strIndent, options) {
283
- if (!obj)
284
- return "";
285
-
286
- strIndent = strIndent || "";
287
- options = options || {};
288
-
289
- var result = "";
290
- var nextIndent = strIndent + " ";
291
- for (var m in obj) {
292
- if (!obj.hasOwnProperty(m))
293
- continue;
294
-
295
- var child = obj[m];
296
-
297
- var validation = !options.optionalToAll && child.required ? "required" : "optional";
298
- if (child.type === "IdRef" && child.reference) {
299
- validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
300
- }
301
-
302
- if (child.validValues && Array.isArray(child.validValues)) {
303
- validation += ", enum(" + encodeHtml(child.validValues.join(", ")) + ")";
304
- }
305
-
306
- if (child.type === "array" && child.items && child.items.type != "object") {
307
- validation += ", array items: " + (!options.optionalToAll && child.items.required ? "required" : "optional");
308
- if (child.items.validValues && Array.isArray(child.items.validValues))
309
- validation += ", enum(" + encodeHtml(child.items.validValues.join(", ")) + ")";
310
- }
311
-
312
- var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
313
-
314
- if (options.mode === "modal") {
315
- if (child.type === "object")
316
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options) + ",";
317
- else if (child.type === "array") {
318
- result += `\r\n${nextIndent}"${m}": [`;
319
- if (child.items.type === "object")
320
- result += " " + comment + formatHintModal(child.items.fields, nextIndent, options);
321
- else if (child.items.type === "datetime")
322
- result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
323
- else if (child.items.type === "boolean")
324
- result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
325
- else if (child.items.type === "integer" || child.items.type === "long"|| child.items.type === "double")
326
- result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
327
- else
328
- result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
329
- result += `]`;
330
- }
331
- else if (child.type === "datetime")
332
- result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
333
- else if (child.type === "boolean")
334
- result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
335
- else if (child.type === "integer" || child.type === "long"|| child.type === "double")
336
- result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
337
- else
338
- result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
339
- } else if (options.mode === "modal_null") {
340
- if (child.type === "object")
341
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
342
- else if (child.type === "array") {
343
- result += `\r\n${nextIndent}"${m}": [`;
344
- if (child.items.type === "object")
345
- result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "],";
346
- else
347
- result += "], " + comment;
348
- }
349
- else
350
- result += `\r\n${nextIndent}"${m}": null, ${comment}`;
351
- } else if (options.mode === "modal_undefined") {
352
- if (child.type === "object")
353
- result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
354
- else if (child.type === "array") {
355
- result += `\r\n${nextIndent}"${m}": [`;
356
- if (child.items.type === "object")
357
- result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "], ";
358
- else
359
- result += "], " + comment;
360
- }
361
- else
362
- result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
363
- } else {
364
- result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
365
- if (child.type === "array")
366
- result += child.items.type === "object" ? " of object" : " of " + child.items.type;
367
- if (child.type === "object")
368
- result += " " + comment + formatHintModal(child.fields, strIndent + " ", options);
369
- else if (child.type === "array" && child.items.type === "object")
370
- result += " " + comment + formatHintModal(child.items.fields, strIndent + " ", options);
371
- else
372
- result += ", " + comment;
373
- }
374
- }
375
-
376
- if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
377
- return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
378
- }
379
-
380
- return result;
381
- }
382
-
383
- function explainRoles(strRoles) {
384
- if (!strRoles)
385
- return "";
386
-
387
- return strRoles.split("|").map(function (item) {
388
- if (item === "*")
389
- return "[Mọi người dùng]";
390
- var roles = item.split("+");
391
- var s = "";
392
- if (roles.length > 1)
393
- s += "(";
394
-
395
- s += roles.join(" và ");
396
-
397
- if (roles.length > 1)
398
- s += ")";
399
-
400
- return s;
401
- }).join(" hoặc ");
402
- }
403
-
404
- function getModalInput(excludedFields, fields, options) {
405
- fields = JSON.parse(JSON.stringify(fields));
406
- if (!fields)
407
- return "";
408
-
409
- options = options || {};
410
-
411
- fields.id = fields.id || {};
412
- fields.id.type = fields.id.type || "AutoId";
413
- fields.id.validation = fields.id.validation || {};
414
- fields.id.validation.required = true;
415
-
416
- if (excludedFields && Array.isArray(excludedFields)) {
417
- if (options.excludeId && fields.id.type === "AutoId")
418
- excludedFields.push("id");
419
-
420
- excludedFields.forEach(function (item) {
421
- var obj = fields;
422
- var segs = item.split(".");
423
- for (var i = 0; i < segs.length; i++) {
424
- if (!obj) return;
425
- var seg = segs[i];
426
- if (!(seg in obj))
427
- return;
428
-
429
- if (i === segs.length - 1)
430
- delete obj[seg];
431
- else if (obj[seg].type === "object")
432
- obj = obj[seg].fields;
433
- else if (obj[seg].type === "array")
434
- obj = obj[seg].items?.fields;
435
- else
436
- return;
437
- }
438
- });
439
- }
440
-
441
- return formatModal(fields, "", { showValidation: true, optionalToAll: options.optionalToAll, mode: options.mode });
442
- }
443
-
444
-
445
- function activeFirstChild() {
446
- $(this).find("> *").eq(0).addClass("active");
447
- }
448
-
449
- $("script[type='text/mt-template']").each(function () {
450
- mt.inlineModuleTemplates[this.id] = this.innerHTML;
451
- });
452
-
453
- var data = {};
454
-
455
- function afterGenerated() {
456
- var domApiName = document.querySelector("#apiName");
457
- if (domApiName)
458
- document.title = domApiName.textContent + " API Document";
459
- }
460
-
461
- function generateDocument() {
462
- // console.log(data);
463
- mt.bindDom(document.body, data);
464
- afterGenerated();
465
- }
466
-
467
- function saveDocument() {
468
- var textFileAsBlob = new Blob(["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML], { type: "application/octet-stream" });
469
-
470
- var downloadLink = document.createElement("a");
471
- //downloadLink.download = data.name + "-docs.html";
472
- downloadLink.download = "docs.html";
473
- if (window.URL) {
474
- // Firefox requires the link to be added to the DOM
475
- // before it can be clicked.
476
- downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
477
- downloadLink.onclick = function () {
478
- document.body.removeChild(downloadLink);
479
- };
480
- downloadLink.style.display = "none";
481
- document.body.appendChild(downloadLink);
482
- } else if (window.webkitURL) {
483
- // Chrome allows the link to be clicked
484
- // without actually adding it to the DOM.
485
- downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
486
- }
487
-
488
- downloadLink.click();
489
- }
490
-
491
- function concat() {
492
- return String.prototype.concat.apply("", arguments);
493
- }
494
-
495
- function getRootApiUrl() {
496
- return window.data.rootUrl;
497
- }
498
-
499
- function getApiDomain() {
500
- var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
501
- if (m)
502
- return m[1];
503
- return "your host";
504
- }
505
-
506
- function getApiPath() {
507
- var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
508
- if (m)
509
- return window.data.rootUrl.substr(m[0].length);
510
- return window.data.rootUrl;
511
- }
512
-
513
- function encodeHtml(data) {
514
- if (data === undefined || data === null)
515
- return "";
516
- var html = typeof data === "string" ? data : data.toString();
517
- html = html.replace(/&/g, "&amp;");
518
- html = html.replace(/</g, "&lt;");
519
- html = html.replace(/>/g, "&gt;");
520
- html = html.replace(/"/g, "&quot;");
521
- html = html.replace(/'/g, "&apos;");
522
- return html;
523
- }
1
+ "use strict";
2
+ function toCSharpName(str) {
3
+ var name = str.replace(/\W/g, "_");
4
+ return name.charAt(0).toUpperCase() + name.substr(1);
5
+ }
6
+ function getHttpMethod(actionName) {
7
+ switch (actionName) {
8
+ case "findMany":
9
+ case "findById":
10
+ return "GET";
11
+ case "createOne":
12
+ case "createMany":
13
+ return "POST";
14
+ case "updateOne":
15
+ case "updateMany":
16
+ return "PUT";
17
+ case "updatePartially":
18
+ return "PATCH";
19
+ case "deleteOne":
20
+ case "deleteMany":
21
+ return "DELETE";
22
+ default:
23
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
24
+ return actionName.substr("_raw_http_method_".length);
25
+ return "UNKNOWN(" + actionName + ")";
26
+ }
27
+ }
28
+ function getPanelClass(actionName) {
29
+ switch (actionName) {
30
+ case "findMany":
31
+ case "findById":
32
+ return "panel panel-primary";
33
+ case "createOne":
34
+ case "createMany":
35
+ return "panel panel-info";
36
+ case "updateOne":
37
+ case "updateMany":
38
+ return "panel panel-warning";
39
+ case "updatePartially":
40
+ return "panel panel-warning";
41
+ case "deleteOne":
42
+ case "deleteMany":
43
+ return "panel panel-danger";
44
+ default:
45
+ return "panel panel-default";
46
+ }
47
+ }
48
+ function getApiUrl(actionName, rootUrl, entityName) {
49
+ switch (actionName) {
50
+ case "findMany":
51
+ case "createOne":
52
+ case "createMany":
53
+ case "updateMany":
54
+ case "deleteMany":
55
+ return rootUrl + entityName + "s";
56
+ case "findById":
57
+ case "updateOne":
58
+ case "updatePartially":
59
+ case "deleteOne":
60
+ return rootUrl + entityName + "s/{" + entityName + "Id}";
61
+ default:
62
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
63
+ return rootUrl + entityName + "s/" + actionName.substr("_raw_http_method_".length);
64
+ return "UNKNOWN(" + actionName + ")";
65
+ }
66
+ }
67
+ function getApiViewUrl(rootUrl, entityName, viewName) {
68
+ return rootUrl + entityName + "s/views/" + viewName;
69
+ }
70
+ function getDescriptionByActionName(actionName, entityName) {
71
+ switch (actionName) {
72
+ case "findMany":
73
+ return "Lấy về danh sách các " + entityName;
74
+ case "findById":
75
+ return "Lấy về một " + entityName + " theo mã của nó";
76
+ case "createOne":
77
+ return "Tạo mới một " + entityName;
78
+ case "createMany":
79
+ return "Tạo mới hàng loạt các " + entityName;
80
+ case "updateOne":
81
+ return "Cập nhật một " + entityName;
82
+ case "updateMany":
83
+ return "Cập nhật hàng loạt các " + entityName;
84
+ case "updatePartially":
85
+ return "Cập nhật một phần dữ liệu của " + entityName;
86
+ case "deleteOne":
87
+ return "Xóa một " + entityName + " theo mã của nó";
88
+ case "deleteMany":
89
+ return "Xóa hàng loạt " + entityName;
90
+ default:
91
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
92
+ return "";
93
+ return "UNKNOWN(" + actionName + ")";
94
+ }
95
+ }
96
+ function getModalOutput(arrFields, fields, options) {
97
+ if (!fields || !arrFields)
98
+ return "";
99
+ var obj = {};
100
+ for (var j = 0; j < arrFields.length; j++) {
101
+ if (!arrFields[j])
102
+ continue;
103
+ var segs = arrFields[j].split('.');
104
+ var objFields = fields;
105
+ var cur = obj;
106
+ for (var i = 0; i < segs.length; i++) {
107
+ if (segs[i] in objFields) {
108
+ var field = objFields[segs[i]];
109
+ if (i === segs.length - 1) {
110
+ if (!(segs[i] in cur))
111
+ cur[segs[i]] = JSON.parse(JSON.stringify(field));
112
+ }
113
+ else if (field.type === "object") {
114
+ objFields = field.fields;
115
+ if (!(segs[i] in cur)) {
116
+ var o = { type: "object", fields: {} };
117
+ cur[segs[i]] = o;
118
+ cur = o.fields;
119
+ }
120
+ else
121
+ cur = cur[segs[i]].fields;
122
+ }
123
+ else if (field.type === "array") {
124
+ objFields = field.items.fields;
125
+ if (!(segs[i] in cur)) {
126
+ var a = { type: "array", items: { type: "object", fields: {} } };
127
+ cur[segs[i]] = a;
128
+ cur = a.items.fields;
129
+ }
130
+ else
131
+ cur = cur[segs[i]].items.fields;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ return formatModal(obj, "", options);
137
+ }
138
+ function formatModal(obj, strIndent, options) {
139
+ if (!obj)
140
+ return "";
141
+ options = options || {};
142
+ var result = "";
143
+ var nextIndent = strIndent + " ";
144
+ for (var m in obj) {
145
+ if (!obj.hasOwnProperty(m))
146
+ continue;
147
+ var child = obj[m];
148
+ var validation = !options.optionalToAll && child.validation && child.validation.required ? "required" : "optional";
149
+ if (child.type === "IdRef" && child.reference) {
150
+ validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
151
+ }
152
+ if (child.validation) {
153
+ if ("validValues" in child.validation)
154
+ validation += ", enum(" + encodeHtml(child.validation.validValues.join(", ")) + ")";
155
+ if ("invalidValues" in child.validation)
156
+ validation += ", not allow(" + encodeHtml(child.validation.invalidValues.join(", ")) + ")";
157
+ if ("pattern" in child.validation)
158
+ validation += ", pattern: /" + encodeHtml(child.validation.pattern) + "/";
159
+ if ("length" in child.validation)
160
+ validation += ", length: " + child.validation.length;
161
+ if ("minLength" in child.validation)
162
+ validation += ", minLength: " + child.validation.minLength;
163
+ if ("maxLength" in child.validation)
164
+ validation += ", maxLength: " + child.validation.maxLength;
165
+ if ("min" in child.validation)
166
+ validation += ", min: " + encodeHtml(child.validation.min);
167
+ if ("max" in child.validation)
168
+ validation += ", max: " + encodeHtml(child.validation.max);
169
+ if ("gt" in child.validation)
170
+ validation += ", gt: " + encodeHtml(child.validation.gt);
171
+ if ("lt" in child.validation)
172
+ validation += ", lt: " + encodeHtml(child.validation.lt);
173
+ }
174
+ if (child.type === "array" && child.items && child.items.type != "object" && child.items.validation) {
175
+ validation += ", array items: " + (!options.optionalToAll && child.items.validation.required ? "required" : "optional");
176
+ if ("validValues" in child.items.validation)
177
+ validation += ", enum(" + encodeHtml(child.items.validation.validValues.join(", ")) + ")";
178
+ if ("invalidValues" in child.items.validation)
179
+ validation += ", not allow(" + encodeHtml(child.items.validation.invalidValues.join(", ")) + ")";
180
+ if ("pattern" in child.items.validation)
181
+ validation += ", pattern: /" + encodeHtml(child.items.validation.pattern) + "/";
182
+ if ("length" in child.items.validation)
183
+ validation += ", length: " + child.items.validation.length;
184
+ if ("minLength" in child.items.validation)
185
+ validation += ", minLength: " + child.items.validation.minLength;
186
+ if ("maxLength" in child.items.validation)
187
+ validation += ", maxLength: " + child.items.validation.maxLength;
188
+ if ("min" in child.items.validation)
189
+ validation += ", min: " + encodeHtml(child.items.validation.min);
190
+ if ("max" in child.items.validation)
191
+ validation += ", max: " + encodeHtml(child.items.validation.max);
192
+ if ("gt" in child.items.validation)
193
+ validation += ", gt: " + encodeHtml(child.items.validation.gt);
194
+ if ("lt" in child.items.validation)
195
+ validation += ", lt: " + encodeHtml(child.items.validation.lt);
196
+ }
197
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
198
+ if (options.mode === "modal") {
199
+ if (child.type === "object")
200
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options) + ",";
201
+ else if (child.type === "array") {
202
+ result += `\r\n${nextIndent}"${m}": [`;
203
+ if (child.items.type === "object")
204
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options);
205
+ else if (child.items.type === "datetime")
206
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
207
+ else if (child.items.type === "boolean")
208
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
209
+ else if (child.items.type === "integer" || child.items.type === "long" || child.items.type === "double")
210
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
211
+ else
212
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
213
+ result += `]`;
214
+ }
215
+ else if (child.type === "datetime")
216
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
217
+ else if (child.type === "boolean")
218
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
219
+ else if (child.type === "integer" || child.type === "long" || child.type === "double")
220
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
221
+ else
222
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
223
+ }
224
+ else if (options.mode === "modal_null") {
225
+ if (child.type === "object")
226
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
227
+ else if (child.type === "array") {
228
+ result += `\r\n${nextIndent}"${m}": [`;
229
+ if (child.items.type === "object")
230
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "],";
231
+ else
232
+ result += "], " + comment;
233
+ }
234
+ else
235
+ result += `\r\n${nextIndent}"${m}": null, ${comment}`;
236
+ }
237
+ else if (options.mode === "modal_undefined") {
238
+ if (child.type === "object")
239
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
240
+ else if (child.type === "array") {
241
+ result += `\r\n${nextIndent}"${m}": [`;
242
+ if (child.items.type === "object")
243
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "], ";
244
+ else
245
+ result += "], " + comment;
246
+ }
247
+ else
248
+ result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
249
+ }
250
+ else {
251
+ result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
252
+ if (child.type === "array")
253
+ result += child.items.type === "object" ? " of object" : " of " + child.items.type;
254
+ if (child.type === "object")
255
+ result += " " + comment + formatModal(child.fields, strIndent + " ", options);
256
+ else if (child.type === "array" && child.items.type === "object")
257
+ result += " " + comment + formatModal(child.items.fields, strIndent + " ", options);
258
+ else
259
+ result += ", " + comment;
260
+ }
261
+ }
262
+ if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
263
+ return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
264
+ }
265
+ return result;
266
+ }
267
+ function formatHintModal(obj, strIndent, options) {
268
+ if (!obj)
269
+ return "";
270
+ strIndent = strIndent || "";
271
+ options = options || {};
272
+ var result = "";
273
+ var nextIndent = strIndent + " ";
274
+ for (var m in obj) {
275
+ if (!obj.hasOwnProperty(m))
276
+ continue;
277
+ var child = obj[m];
278
+ var validation = !options.optionalToAll && child.required ? "required" : "optional";
279
+ if (child.type === "IdRef" && child.reference) {
280
+ validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
281
+ }
282
+ if (child.validValues && Array.isArray(child.validValues)) {
283
+ validation += ", enum(" + encodeHtml(child.validValues.join(", ")) + ")";
284
+ }
285
+ if (child.type === "array" && child.items && child.items.type != "object") {
286
+ validation += ", array items: " + (!options.optionalToAll && child.items.required ? "required" : "optional");
287
+ if (child.items.validValues && Array.isArray(child.items.validValues))
288
+ validation += ", enum(" + encodeHtml(child.items.validValues.join(", ")) + ")";
289
+ }
290
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
291
+ if (options.mode === "modal") {
292
+ if (child.type === "object")
293
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options) + ",";
294
+ else if (child.type === "array") {
295
+ result += `\r\n${nextIndent}"${m}": [`;
296
+ if (child.items.type === "object")
297
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options);
298
+ else if (child.items.type === "datetime")
299
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
300
+ else if (child.items.type === "boolean")
301
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
302
+ else if (child.items.type === "integer" || child.items.type === "long" || child.items.type === "double")
303
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
304
+ else
305
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
306
+ result += `]`;
307
+ }
308
+ else if (child.type === "datetime")
309
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
310
+ else if (child.type === "boolean")
311
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
312
+ else if (child.type === "integer" || child.type === "long" || child.type === "double")
313
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
314
+ else
315
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
316
+ }
317
+ else if (options.mode === "modal_null") {
318
+ if (child.type === "object")
319
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
320
+ else if (child.type === "array") {
321
+ result += `\r\n${nextIndent}"${m}": [`;
322
+ if (child.items.type === "object")
323
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "],";
324
+ else
325
+ result += "], " + comment;
326
+ }
327
+ else
328
+ result += `\r\n${nextIndent}"${m}": null, ${comment}`;
329
+ }
330
+ else if (options.mode === "modal_undefined") {
331
+ if (child.type === "object")
332
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
333
+ else if (child.type === "array") {
334
+ result += `\r\n${nextIndent}"${m}": [`;
335
+ if (child.items.type === "object")
336
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "], ";
337
+ else
338
+ result += "], " + comment;
339
+ }
340
+ else
341
+ result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
342
+ }
343
+ else {
344
+ result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
345
+ if (child.type === "array")
346
+ result += child.items.type === "object" ? " of object" : " of " + child.items.type;
347
+ if (child.type === "object")
348
+ result += " " + comment + formatHintModal(child.fields, strIndent + " ", options);
349
+ else if (child.type === "array" && child.items.type === "object")
350
+ result += " " + comment + formatHintModal(child.items.fields, strIndent + " ", options);
351
+ else
352
+ result += ", " + comment;
353
+ }
354
+ }
355
+ if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
356
+ return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
357
+ }
358
+ return result;
359
+ }
360
+ function explainRoles(strRoles) {
361
+ if (!strRoles)
362
+ return "";
363
+ return strRoles.split("|").map(function (item) {
364
+ if (item === "*")
365
+ return "[Mọi người dùng]";
366
+ var roles = item.split("+");
367
+ var s = "";
368
+ if (roles.length > 1)
369
+ s += "(";
370
+ s += roles.join(" và ");
371
+ if (roles.length > 1)
372
+ s += ")";
373
+ return s;
374
+ }).join(" hoặc ");
375
+ }
376
+ function getModalInput(excludedFields, fields, options) {
377
+ fields = JSON.parse(JSON.stringify(fields));
378
+ if (!fields)
379
+ return "";
380
+ options = options || {};
381
+ fields.id = fields.id || {};
382
+ fields.id.type = fields.id.type || "AutoId";
383
+ fields.id.validation = fields.id.validation || {};
384
+ fields.id.validation.required = true;
385
+ if (excludedFields && Array.isArray(excludedFields)) {
386
+ if (options.excludeId && fields.id.type === "AutoId")
387
+ excludedFields.push("id");
388
+ excludedFields.forEach(function (item) {
389
+ var obj = fields;
390
+ var segs = item.split(".");
391
+ for (var i = 0; i < segs.length; i++) {
392
+ if (!obj)
393
+ return;
394
+ var seg = segs[i];
395
+ if (!(seg in obj))
396
+ return;
397
+ if (i === segs.length - 1)
398
+ delete obj[seg];
399
+ else if (obj[seg].type === "object")
400
+ obj = obj[seg].fields;
401
+ else if (obj[seg].type === "array")
402
+ obj = obj[seg].items?.fields;
403
+ else
404
+ return;
405
+ }
406
+ });
407
+ }
408
+ return formatModal(fields, "", { showValidation: true, optionalToAll: options.optionalToAll, mode: options.mode });
409
+ }
410
+ function activeFirstChild() {
411
+ $(this).find("> *").eq(0).addClass("active");
412
+ }
413
+ $("script[type='text/mt-template']").each(function () {
414
+ mt.inlineModuleTemplates[this.id] = this.innerHTML;
415
+ });
416
+ var data = {};
417
+ function afterGenerated() {
418
+ var domApiName = document.querySelector("#apiName");
419
+ if (domApiName)
420
+ document.title = domApiName.textContent + " API Document";
421
+ }
422
+ function generateDocument() {
423
+ mt.bindDom(document.body, data);
424
+ afterGenerated();
425
+ }
426
+ function saveDocument() {
427
+ var textFileAsBlob = new Blob(["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML], { type: "application/octet-stream" });
428
+ var downloadLink = document.createElement("a");
429
+ downloadLink.download = "docs.html";
430
+ if (window.URL) {
431
+ downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
432
+ downloadLink.onclick = function () {
433
+ document.body.removeChild(downloadLink);
434
+ };
435
+ downloadLink.style.display = "none";
436
+ document.body.appendChild(downloadLink);
437
+ }
438
+ else if (window.webkitURL) {
439
+ downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
440
+ }
441
+ downloadLink.click();
442
+ }
443
+ function concat() {
444
+ return String.prototype.concat.apply("", arguments);
445
+ }
446
+ function getRootApiUrl() {
447
+ return window.data.rootUrl;
448
+ }
449
+ function getApiDomain() {
450
+ var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
451
+ if (m)
452
+ return m[1];
453
+ return "your host";
454
+ }
455
+ function getApiPath() {
456
+ var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
457
+ if (m)
458
+ return window.data.rootUrl.substr(m[0].length);
459
+ return window.data.rootUrl;
460
+ }
461
+ function encodeHtml(data) {
462
+ if (data === undefined || data === null)
463
+ return "";
464
+ var html = typeof data === "string" ? data : data.toString();
465
+ html = html.replace(/&/g, "&amp;");
466
+ html = html.replace(/</g, "&lt;");
467
+ html = html.replace(/>/g, "&gt;");
468
+ html = html.replace(/"/g, "&quot;");
469
+ html = html.replace(/'/g, "&apos;");
470
+ return html;
471
+ }