mushroom-cli 1.1.0-alpha.12 → 1.1.0-alpha.15

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/docs/doc-mt.js ADDED
@@ -0,0 +1,421 @@
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 explainRoles(strRoles) {
283
+ if (!strRoles)
284
+ return "";
285
+
286
+ return strRoles.split("|").map(function (item) {
287
+ if (item === "*")
288
+ return "[Mọi người dùng]";
289
+ var roles = item.split("+");
290
+ var s = "";
291
+ if (roles.length > 1)
292
+ s += "(";
293
+
294
+ s += roles.join(" và ");
295
+
296
+ if (roles.length > 1)
297
+ s += ")";
298
+
299
+ return s;
300
+ }).join(" hoặc ");
301
+ }
302
+
303
+ function getModalInput(excludedFields, fields, options) {
304
+ fields = JSON.parse(JSON.stringify(fields));
305
+ if (!fields)
306
+ return "";
307
+
308
+ options = options || {};
309
+
310
+ fields.id = fields.id || {};
311
+ fields.id.type = fields.id.type || "AutoId";
312
+ fields.id.validation = fields.id.validation || {};
313
+ fields.id.validation.required = true;
314
+
315
+ if (excludedFields && Array.isArray(excludedFields)) {
316
+ if (options.excludeId && fields.id.type === "AutoId")
317
+ excludedFields.push("id");
318
+
319
+ excludedFields.forEach(function (item) {
320
+ var obj = fields;
321
+ var segs = item.split(".");
322
+ for (var i = 0; i < segs.length; i++) {
323
+ var seg = segs[i];
324
+ if (!(seg in obj))
325
+ return;
326
+
327
+ if (i === segs.length - 1)
328
+ delete obj[seg];
329
+ else if (obj[seg].type === "object")
330
+ obj = obj[seg].fields;
331
+ else if (obj[seg].type === "array")
332
+ obj = obj[seg].items;
333
+ else
334
+ return;
335
+ }
336
+ });
337
+ }
338
+
339
+ return formatModal(fields, "", { showValidation: true, optionalToAll: options.optionalToAll, mode: options.mode });
340
+ }
341
+
342
+
343
+ function activeFirstChild() {
344
+ $(this).find("> *").eq(0).addClass("active");
345
+ }
346
+
347
+ $("script[type='text/mt-template']").each(function () {
348
+ mt.inlineModuleTemplates[this.id] = this.innerHTML;
349
+ });
350
+
351
+ var data = {};
352
+
353
+ function afterGenerated() {
354
+ var domApiName = document.querySelector("#apiName");
355
+ if (domApiName)
356
+ document.title = domApiName.textContent + " API Document";
357
+ }
358
+
359
+ function generateDocument() {
360
+ // console.log(data);
361
+ mt.bindDom(document.body, data);
362
+ afterGenerated();
363
+ }
364
+
365
+ function saveDocument() {
366
+ var textFileAsBlob = new Blob(["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML], { type: "application/octet-stream" });
367
+
368
+ var downloadLink = document.createElement("a");
369
+ //downloadLink.download = data.name + "-docs.html";
370
+ downloadLink.download = "docs.html";
371
+ if (window.URL) {
372
+ // Firefox requires the link to be added to the DOM
373
+ // before it can be clicked.
374
+ downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
375
+ downloadLink.onclick = function () {
376
+ document.body.removeChild(downloadLink);
377
+ };
378
+ downloadLink.style.display = "none";
379
+ document.body.appendChild(downloadLink);
380
+ } else if (window.webkitURL) {
381
+ // Chrome allows the link to be clicked
382
+ // without actually adding it to the DOM.
383
+ downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
384
+ }
385
+
386
+ downloadLink.click();
387
+ }
388
+
389
+ function concat() {
390
+ return String.prototype.concat.apply("", arguments);
391
+ }
392
+
393
+ function getRootApiUrl() {
394
+ return window.data.rootUrl;
395
+ }
396
+
397
+ function getApiDomain() {
398
+ var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
399
+ if (m)
400
+ return m[1];
401
+ return "your host";
402
+ }
403
+
404
+ function getApiPath() {
405
+ var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
406
+ if (m)
407
+ return window.data.rootUrl.substr(m[0].length);
408
+ return window.data.rootUrl;
409
+ }
410
+
411
+ function encodeHtml(data) {
412
+ if (data === undefined || data === null)
413
+ return "";
414
+ var html = typeof data === "string" ? data : data.toString();
415
+ html = html.replace(/&/g, "&amp;");
416
+ html = html.replace(/</g, "&lt;");
417
+ html = html.replace(/>/g, "&gt;");
418
+ html = html.replace(/"/g, "&quot;");
419
+ html = html.replace(/'/g, "&apos;");
420
+ return html;
421
+ }