mushroom-cli 1.2.0-alpha.2 → 1.2.0-alpha.21

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 (46) hide show
  1. package/README.md +280 -111
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +272 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/bootstrap-theme.min.css +6 -0
  6. package/dist/docs/bootstrap.min.css +6 -0
  7. package/dist/docs/bootstrap.min.js +7 -0
  8. package/{docs → dist/docs}/doc-mt.js +103 -1
  9. package/{docs → dist/docs}/docs.html +83 -22
  10. package/dist/docs/docs.v2.html +5086 -0
  11. package/dist/docs/docs.v2.js +1922 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/gen/gen-api-docs-v1.js +110 -0
  14. package/dist/gen/gen-api-docs.js +306 -0
  15. package/{gen → dist/gen}/gen-csharp.js +1246 -1414
  16. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  17. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  18. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  19. package/dist/gen/gen-ts-driver.js +596 -0
  20. package/{gen.js → dist/gen.js} +109 -120
  21. package/{help.js → dist/help.js} +53 -55
  22. package/dist/init/init-json.js +92 -0
  23. package/dist/init/init-netcore.js +30 -0
  24. package/dist/init.js +23 -0
  25. package/dist/master-file/master-file.js +185 -0
  26. package/dist/merge.js +70 -0
  27. package/dist/mr.js +77 -0
  28. package/dist/types.js +1 -0
  29. package/dist/update/tsCode.js +82 -0
  30. package/dist/update.js +20 -0
  31. package/package.json +64 -27
  32. package/check-update.js +0 -9
  33. package/common.js +0 -236
  34. package/config.js +0 -445
  35. package/gen/gen-api-docs.js +0 -125
  36. package/gen/gen-ts-driver.js +0 -460
  37. package/init/init-json.js +0 -106
  38. package/init/init-netcore.js +0 -32
  39. package/init.js +0 -28
  40. package/master-file/master-file.js +0 -234
  41. package/merge.js +0 -84
  42. package/mr.js +0 -82
  43. package/update/tsCode.js +0 -20
  44. package/update.js +0 -24
  45. /package/{docs → dist/docs}/mt-dom-1.0.js +0 -0
  46. /package/{docs → dist/docs}/mt.extension.js +0 -0
@@ -0,0 +1,1922 @@
1
+ function toCSharpName(str) {
2
+ if (typeof str != 'string' || str === '') return '';
3
+ const name = str.replace(/\W/g, '_');
4
+ return name.charAt(0).toUpperCase() + name.substring(1);
5
+ }
6
+ function encodeHtml(data) {
7
+ if (data === undefined || data === null) return '';
8
+ var html = typeof data === 'string' ? data : data.toString();
9
+ html = html.replace(/&/g, '&');
10
+ html = html.replace(/</g, '&lt;');
11
+ html = html.replace(/>/g, '&gt;');
12
+ html = html.replace(/"/g, '&quot;');
13
+ html = html.replace(/'/g, '&apos;');
14
+ return html;
15
+ }
16
+ function populateTemplates() {
17
+ const templates = {};
18
+ document.querySelectorAll('.mushroom-docs-template').forEach((dom) => {
19
+ templates[dom.id] = dom.innerHTML;
20
+ dom.remove();
21
+ });
22
+ window.templates = templates;
23
+ }
24
+ function renderTemplate(templateId, data) {
25
+ const template = window.templates[templateId];
26
+ if (!template) return '';
27
+ return template.replace(/\{\{(\w+)(:html)?\}\}/g, (_, field, format) =>
28
+ format === ':html' ? (data?.[field] ?? '') : encodeHtml(data?.[field]),
29
+ );
30
+ }
31
+
32
+ function getApiDomain(url) {
33
+ const m = url.match(/^(\w+:)?\/\/(([\w-]+\.)+\w+(:\d+)?)/);
34
+ return m ? m[2] : 'your host';
35
+ }
36
+ function getApiPath(url) {
37
+ const m = url.match(/^(\w+:)?\/\/([\w-]+\.)+\w+(:\d+)?/);
38
+ return m ? url.substring(m[0].length) : url;
39
+ }
40
+
41
+ function getPanelClass(actionName) {
42
+ switch (actionName) {
43
+ case 'findMany':
44
+ case 'findById':
45
+ return 'panel panel-primary';
46
+ case 'createOne':
47
+ case 'createMany':
48
+ return 'panel panel-info';
49
+ case 'updateOne':
50
+ case 'updateMany':
51
+ return 'panel panel-warning';
52
+ case 'updatePartially':
53
+ return 'panel panel-warning';
54
+ case 'deleteOne':
55
+ case 'deleteMany':
56
+ return 'panel panel-danger';
57
+ default:
58
+ return 'panel panel-default';
59
+ }
60
+ }
61
+ function getHttpMethod(actionName) {
62
+ switch (actionName) {
63
+ case 'findMany':
64
+ case 'findById':
65
+ return 'GET';
66
+ case 'createOne':
67
+ case 'createMany':
68
+ return 'POST';
69
+ case 'updateOne':
70
+ case 'updateMany':
71
+ return 'PUT';
72
+ case 'updatePartially':
73
+ return 'PATCH';
74
+ case 'deleteOne':
75
+ case 'deleteMany':
76
+ return 'DELETE';
77
+ default:
78
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1)
79
+ return actionName.substring('_raw_http_method_'.length);
80
+ return 'UNKNOWN(' + actionName + ')';
81
+ }
82
+ }
83
+ function getApiUrl(actionName, rootUrl, entityName) {
84
+ switch (actionName) {
85
+ case 'findMany':
86
+ case 'createOne':
87
+ case 'createMany':
88
+ case 'updateMany':
89
+ case 'deleteMany':
90
+ return rootUrl + entityName + 's';
91
+ case 'findById':
92
+ case 'updateOne':
93
+ case 'updatePartially':
94
+ case 'deleteOne':
95
+ return rootUrl + entityName + 's/{' + entityName + 'Id}';
96
+ default:
97
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1)
98
+ return rootUrl + entityName + 's/' + actionName.substring('_raw_http_method_'.length);
99
+ return 'UNKNOWN(' + actionName + ')';
100
+ }
101
+ }
102
+ function getApiViewUrl(rootUrl, entityName, viewName) {
103
+ return rootUrl + entityName + 's/views/' + viewName;
104
+ }
105
+ function getDescriptionByActionName(actionName, entityName) {
106
+ switch (actionName) {
107
+ case 'findMany':
108
+ return 'Lấy về danh sách các ' + entityName;
109
+ case 'findById':
110
+ return 'Lấy về một ' + entityName + ' theo mã của nó';
111
+ case 'createOne':
112
+ return 'Tạo mới một ' + entityName;
113
+ case 'createMany':
114
+ return 'Tạo mới hàng loạt các ' + entityName;
115
+ case 'updateOne':
116
+ return 'Cập nhật một ' + entityName;
117
+ case 'updateMany':
118
+ return 'Cập nhật hàng loạt các ' + entityName;
119
+ case 'updatePartially':
120
+ return 'Cập nhật một phần dữ liệu của ' + entityName;
121
+ case 'deleteOne':
122
+ return 'Xóa một ' + entityName + ' theo mã của nó';
123
+ case 'deleteMany':
124
+ return 'Xóa hàng loạt ' + entityName;
125
+ default:
126
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1) return '';
127
+ return 'UNKNOWN(' + actionName + ')';
128
+ }
129
+ }
130
+ function explainRoles(strRoles) {
131
+ if (!strRoles) return '';
132
+
133
+ return strRoles
134
+ .split('|')
135
+ .map(function (item) {
136
+ if (item === '*') return '[Mọi người dùng]';
137
+ const roles = item.split('+');
138
+ let s = '';
139
+ if (roles.length > 1) s += '(';
140
+
141
+ s += roles.join(' và ');
142
+
143
+ if (roles.length > 1) s += ')';
144
+
145
+ return s;
146
+ })
147
+ .join(' hoặc ');
148
+ }
149
+ function getModelOutput(arrFields, fields, options) {
150
+ if (!fields || !arrFields) return '';
151
+
152
+ var obj = {};
153
+ for (var j = 0; j < arrFields.length; j++) {
154
+ if (!arrFields[j]) continue;
155
+ var segs = arrFields[j].split('.');
156
+ var objFields = fields;
157
+ var cur = obj;
158
+ for (var i = 0; i < segs.length; i++) {
159
+ if (segs[i] in objFields) {
160
+ var field = objFields[segs[i]];
161
+
162
+ if (i === segs.length - 1) {
163
+ if (!(segs[i] in cur)) cur[segs[i]] = JSON.parse(JSON.stringify(field));
164
+ } else if (field.type === 'object') {
165
+ objFields = field.fields;
166
+ if (!(segs[i] in cur)) {
167
+ var o = { type: 'object', fields: {} };
168
+ cur[segs[i]] = o;
169
+ cur = o.fields;
170
+ } else cur = cur[segs[i]].fields;
171
+ } else if (field.type === 'array') {
172
+ objFields = field.items.fields;
173
+ if (!(segs[i] in cur)) {
174
+ var a = { type: 'array', items: { type: 'object', fields: {} } };
175
+ cur[segs[i]] = a;
176
+ cur = a.items.fields;
177
+ } else cur = cur[segs[i]].items.fields;
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ return formatModel(obj, '', options).trim();
184
+ }
185
+ function formatModel(obj, strIndent, options) {
186
+ if (!obj) return '';
187
+
188
+ options = options || {};
189
+
190
+ var result = '';
191
+ var nextIndent = strIndent + ' ';
192
+ for (var m in obj) {
193
+ if (!obj.hasOwnProperty(m)) continue;
194
+
195
+ var child = obj[m];
196
+
197
+ var validation = !options.optionalToAll && child.validation && child.validation.required ? 'required' : 'optional';
198
+ if (child.type === 'IdRef' && child.reference) {
199
+ validation +=
200
+ ", ref: <a href='#" +
201
+ encodeHtml(child.reference) +
202
+ "' onclick='setTimeout(gotoHash, 20)'>" +
203
+ encodeHtml(child.reference) +
204
+ '</a>';
205
+ }
206
+
207
+ if (child.validation) {
208
+ if ('validValues' in child.validation)
209
+ validation += ', enum(' + encodeHtml(child.validation.validValues.join(', ')) + ')';
210
+ if ('invalidValues' in child.validation)
211
+ validation += ', not allow(' + encodeHtml(child.validation.invalidValues.join(', ')) + ')';
212
+ if ('pattern' in child.validation) validation += ', pattern: /' + encodeHtml(child.validation.pattern) + '/';
213
+ if ('length' in child.validation) validation += ', length: ' + child.validation.length;
214
+ if ('minLength' in child.validation) validation += ', minLength: ' + child.validation.minLength;
215
+ if ('maxLength' in child.validation) validation += ', maxLength: ' + child.validation.maxLength;
216
+ if ('min' in child.validation) validation += ', min: ' + encodeHtml(child.validation.min);
217
+ if ('max' in child.validation) validation += ', max: ' + encodeHtml(child.validation.max);
218
+ if ('gt' in child.validation) validation += ', gt: ' + encodeHtml(child.validation.gt);
219
+ if ('lt' in child.validation) validation += ', lt: ' + encodeHtml(child.validation.lt);
220
+ }
221
+
222
+ if (child.type === 'array' && child.items && child.items.type != 'object' && child.items.validation) {
223
+ validation +=
224
+ ', array items: ' + (!options.optionalToAll && child.items.validation.required ? 'required' : 'optional');
225
+ if ('validValues' in child.items.validation)
226
+ validation += ', enum(' + encodeHtml(child.items.validation.validValues.join(', ')) + ')';
227
+ if ('invalidValues' in child.items.validation)
228
+ validation += ', not allow(' + encodeHtml(child.items.validation.invalidValues.join(', ')) + ')';
229
+ if ('pattern' in child.items.validation)
230
+ validation += ', pattern: /' + encodeHtml(child.items.validation.pattern) + '/';
231
+ if ('length' in child.items.validation) validation += ', length: ' + child.items.validation.length;
232
+ if ('minLength' in child.items.validation) validation += ', minLength: ' + child.items.validation.minLength;
233
+ if ('maxLength' in child.items.validation) validation += ', maxLength: ' + child.items.validation.maxLength;
234
+ if ('min' in child.items.validation) validation += ', min: ' + encodeHtml(child.items.validation.min);
235
+ if ('max' in child.items.validation) validation += ', max: ' + encodeHtml(child.items.validation.max);
236
+ if ('gt' in child.items.validation) validation += ', gt: ' + encodeHtml(child.items.validation.gt);
237
+ if ('lt' in child.items.validation) validation += ', lt: ' + encodeHtml(child.items.validation.lt);
238
+ }
239
+
240
+ let defaultValueDocs = '';
241
+ if (options.showDefaultValue && child.defaultValue !== undefined && child.defaultValue !== null) {
242
+ defaultValueDocs = `, default: ${encodeHtml(child.type === 'string' ? JSON.stringify(child.defaultValue) : child.defaultValue)}`;
243
+ }
244
+
245
+ var comment = `<span class="code-comment">// ${validation}${defaultValueDocs} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description) : ''}</span>`;
246
+
247
+ if (options.mode === 'model') {
248
+ if (child.type === 'object')
249
+ result +=
250
+ '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(child.fields, nextIndent, options) + ',';
251
+ else if (child.type === 'array') {
252
+ result += `\r\n${nextIndent}"${m}": [`;
253
+ if (child.items.type === 'object')
254
+ result += ' ' + comment + formatModel(child.items.fields, nextIndent, options);
255
+ else if (child.items.type === 'datetime')
256
+ result +=
257
+ `\r\n${nextIndent} ` +
258
+ JSON.stringify(child.items.defaultValue || 'ISODate_ISO_8601') +
259
+ ' ' +
260
+ comment +
261
+ `\r\n${nextIndent}`;
262
+ else if (child.items.type === 'boolean')
263
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || 'false' + ' ' + comment + `\r\n${nextIndent}`;
264
+ else if (child.items.type === 'integer' || child.items.type === 'long' || child.items.type === 'double')
265
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || '0' + ' ' + comment + `\r\n${nextIndent}`;
266
+ else
267
+ result +=
268
+ `\r\n${nextIndent} ` +
269
+ JSON.stringify(child.defaultValue || child.type) +
270
+ ' ' +
271
+ comment +
272
+ `\r\n${nextIndent}`;
273
+ result += `]`;
274
+ } else if (child.type === 'datetime')
275
+ result +=
276
+ `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || 'ISODate_ISO_8601') + ', ' + comment;
277
+ else if (child.type === 'boolean')
278
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || 'false') + ', ' + comment;
279
+ else if (child.type === 'integer' || child.type === 'long' || child.type === 'double')
280
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || '0') + ', ' + comment;
281
+ else result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ', ' + comment;
282
+ } else if (options.mode === 'model_null') {
283
+ if (child.type === 'object')
284
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(child.fields, nextIndent, options);
285
+ else if (child.type === 'array') {
286
+ result += `\r\n${nextIndent}"${m}": [`;
287
+ if (child.items.type === 'object')
288
+ result += ' ' + comment + formatModel(child.items.fields, nextIndent, options) + '],';
289
+ else result += '], ' + comment;
290
+ } else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
291
+ } else if (options.mode === 'model_undefined') {
292
+ if (child.type === 'object')
293
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(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 + formatModel(child.items.fields, nextIndent, options) + '], ';
298
+ else result += '], ' + comment;
299
+ } else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
300
+ } else {
301
+ result += '\r\n' + strIndent + encodeHtml(m) + ': ' + encodeHtml(child.type);
302
+ if (child.type === 'array') result += child.items.type === 'object' ? ' of object' : ' of ' + child.items.type;
303
+ if (child.type === 'object') result += ' ' + comment + formatModel(child.fields, strIndent + ' ', options);
304
+ else if (child.type === 'array' && child.items.type === 'object')
305
+ result += ' ' + comment + formatModel(child.items.fields, strIndent + ' ', options);
306
+ else result += ', ' + comment;
307
+ }
308
+ }
309
+
310
+ if (options.mode === 'model' || options.mode === 'model_null' || options.mode === 'model_undefined') {
311
+ return (strIndent ? '\r\n' + strIndent : '') + '{' + result + '\r\n' + strIndent + '}';
312
+ }
313
+
314
+ return result;
315
+ }
316
+ function toCachePolicyString(cachePolicy) {
317
+ if (cachePolicy === undefined || cachePolicy === null || cachePolicy === 'unset') return 'Không thiết lập cấu hình';
318
+ if (cachePolicy === 'required') return 'Bắt buộc phải cache';
319
+ if (cachePolicy === 'allow') return 'Cho phép';
320
+ if (cachePolicy === 'disabled') return 'Bắt buộc không được cache';
321
+ return '';
322
+ }
323
+ function getModelInput(excludedFields, fields, options) {
324
+ fields = JSON.parse(JSON.stringify(fields));
325
+ if (!fields) return '';
326
+
327
+ options = options || {};
328
+
329
+ fields.id = fields.id || {};
330
+ fields.id.type = fields.id.type || 'AutoId';
331
+ fields.id.validation = fields.id.validation || {};
332
+ fields.id.validation.required = true;
333
+
334
+ if (excludedFields && Array.isArray(excludedFields)) {
335
+ if (options.excludeId && fields.id.type === 'AutoId') {
336
+ excludedFields = [...excludedFields, 'id'];
337
+ }
338
+
339
+ excludedFields.forEach((item) => {
340
+ let obj = fields;
341
+ const segs = item.split('.');
342
+ for (let i = 0; i < segs.length; i++) {
343
+ if (!obj) return;
344
+ const seg = segs[i];
345
+ if (!(seg in obj)) return;
346
+
347
+ if (i === segs.length - 1) delete obj[seg];
348
+ else if (obj[seg].type === 'object') obj = obj[seg].fields;
349
+ else if (obj[seg].type === 'array') obj = obj[seg].items?.fields;
350
+ else return;
351
+ }
352
+ });
353
+ }
354
+
355
+ return formatModel(fields, '', { ...options, showValidation: true }).trim();
356
+ }
357
+ function formatHintModel(obj, strIndent, options) {
358
+ if (!obj) return '';
359
+
360
+ strIndent = strIndent || '';
361
+ options = options || {};
362
+
363
+ var result = '';
364
+ var nextIndent = strIndent + ' ';
365
+ for (var m in obj) {
366
+ if (!obj.hasOwnProperty(m)) continue;
367
+
368
+ var child = obj[m];
369
+
370
+ var validation = !options.optionalToAll && child.required ? 'required' : 'optional';
371
+ if (child.type === 'IdRef' && child.reference) {
372
+ validation +=
373
+ ", ref: <a href='#" +
374
+ encodeHtml(child.reference) +
375
+ "' onclick='setTimeout(gotoHash, 20)'>" +
376
+ encodeHtml(child.reference) +
377
+ '</a>';
378
+ }
379
+
380
+ if (child.validValues && Array.isArray(child.validValues)) {
381
+ validation += ', enum(' + encodeHtml(child.validValues.join(', ')) + ')';
382
+ }
383
+
384
+ if (child.type === 'array' && child.items && child.items.type != 'object') {
385
+ validation += ', array items: ' + (!options.optionalToAll && child.items.required ? 'required' : 'optional');
386
+ if (child.items.validValues && Array.isArray(child.items.validValues))
387
+ validation += ', enum(' + encodeHtml(child.items.validValues.join(', ')) + ')';
388
+ }
389
+
390
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description).replace(/\n/g, ' ') : ''}</span>`;
391
+
392
+ if (options.mode === 'model') {
393
+ if (child.type === 'object')
394
+ result +=
395
+ '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options) + ',';
396
+ else if (child.type === 'array') {
397
+ result += `\r\n${nextIndent}"${m}": [`;
398
+ if (child.items.type === 'object')
399
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options);
400
+ else if (child.items.type === 'datetime')
401
+ result +=
402
+ `\r\n${nextIndent} ` +
403
+ JSON.stringify(child.items.defaultValue || 'ISODate_ISO_8601') +
404
+ ' ' +
405
+ comment +
406
+ `\r\n${nextIndent}`;
407
+ else if (child.items.type === 'boolean')
408
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || 'false' + ' ' + comment + `\r\n${nextIndent}`;
409
+ else if (child.items.type === 'integer' || child.items.type === 'long' || child.items.type === 'double')
410
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || '0' + ' ' + comment + `\r\n${nextIndent}`;
411
+ else
412
+ result +=
413
+ `\r\n${nextIndent} ` +
414
+ JSON.stringify(child.defaultValue || child.type) +
415
+ ' ' +
416
+ comment +
417
+ `\r\n${nextIndent}`;
418
+ result += `]`;
419
+ } else if (child.type === 'datetime')
420
+ result +=
421
+ `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || 'ISODate_ISO_8601') + ', ' + comment;
422
+ else if (child.type === 'boolean')
423
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || 'false') + ', ' + comment;
424
+ else if (child.type === 'integer' || child.type === 'long' || child.type === 'double')
425
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || '0') + ', ' + comment;
426
+ else result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ', ' + comment;
427
+ } else if (options.mode === 'model_null') {
428
+ if (child.type === 'object')
429
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options);
430
+ else if (child.type === 'array') {
431
+ result += `\r\n${nextIndent}"${m}": [`;
432
+ if (child.items.type === 'object')
433
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options) + '],';
434
+ else result += '], ' + comment;
435
+ } else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
436
+ } else if (options.mode === 'model_undefined') {
437
+ if (child.type === 'object')
438
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options);
439
+ else if (child.type === 'array') {
440
+ result += `\r\n${nextIndent}"${m}": [`;
441
+ if (child.items.type === 'object')
442
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options) + '], ';
443
+ else result += '], ' + comment;
444
+ } else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
445
+ } else {
446
+ result += '\r\n' + strIndent + encodeHtml(m) + ': ' + encodeHtml(child.type);
447
+ if (child.type === 'array') result += child.items.type === 'object' ? ' of object' : ' of ' + child.items.type;
448
+ if (child.type === 'object') result += ' ' + comment + formatHintModel(child.fields, strIndent + ' ', options);
449
+ else if (child.type === 'array' && child.items.type === 'object')
450
+ result += ' ' + comment + formatHintModel(child.items.fields, strIndent + ' ', options);
451
+ else result += ', ' + comment;
452
+ }
453
+ }
454
+
455
+ if (options.mode === 'model' || options.mode === 'model_null' || options.mode === 'model_undefined') {
456
+ return (strIndent ? '\r\n' + strIndent : '') + '{' + result + '\r\n' + strIndent + '}';
457
+ }
458
+
459
+ return result;
460
+ }
461
+
462
+ function renderInfo() {
463
+ document.title = document.querySelector('#project-title').innerText = window.docs.info.name + ' API document';
464
+ document.querySelector('#project-description').innerText = window.docs.info.description;
465
+
466
+ document.querySelector('#project-roles').innerHTML =
467
+ window.docs.roles.map((role) => renderTemplate('template-project-role', role)).join('') ?? '';
468
+
469
+ if (window.docs.info.security?.crossDomain === false) {
470
+ document.querySelector('#project-security-crossDomain-false').style.display = 'block';
471
+ }
472
+ if (
473
+ window.docs.info.security?.crossDomain === true &&
474
+ Array.isArray(window.docs.info.security.allowOrigins) &&
475
+ window.docs.info.security.allowOrigins.length &&
476
+ !window.docs.info.security.allowOrigins.includes('*')
477
+ ) {
478
+ document.querySelector('#project-security-allowOrigins').style.display = 'block';
479
+ document.querySelector('#project-security-allowOrigins ul').innerHTML = window.docs.info.security.allowOrigins
480
+ .map((origin) => renderTemplate('template-li-code', { value: origin }))
481
+ .join('');
482
+ }
483
+
484
+ const domRootUrls = document.querySelector('#project-rootUrls');
485
+ const rootUrls = Object.keys(localStorage)
486
+ .filter((key) => localStorage.hasOwnProperty(key) && key.startsWith('rootUrl.'))
487
+ .map((key) => key.substring(8));
488
+ if (!rootUrls.includes(window.docs.info.rootUrl)) rootUrls.unshift(window.docs.info.rootUrl);
489
+
490
+ let selected = localStorage.selected_root_url;
491
+ if (!selected) selected = localStorage.selected_root_url = window.docs.info.rootUrl;
492
+ const onspanclick = function () {
493
+ this.parentNode.parentNode.querySelector('.selected').className = '';
494
+ selected = this.innerText;
495
+ this.className = 'selected';
496
+ const old_root_url = localStorage.selected_root_url;
497
+ const new_root_url = this.innerText;
498
+ localStorage.selected_root_url = new_root_url;
499
+ document
500
+ .querySelectorAll('.contain-root-url')
501
+ .forEach((dom) => (dom.innerHTML = dom.innerHTML.replace(old_root_url, new_root_url)));
502
+ document.querySelectorAll('.root-url').forEach((dom) => (dom.innerText = new_root_url));
503
+ document.querySelectorAll('.domain').forEach((dom) => (dom.innerText = getApiDomain(new_root_url)));
504
+ };
505
+ const onlabelclick = function () {
506
+ const span = this.parentNode.querySelector('span');
507
+ if (span.className == 'selected') return;
508
+
509
+ const rootUrl = span.innerText;
510
+ const index = rootUrls.indexOf(rootUrl);
511
+ if (index !== -1) rootUrls.splice(index, 1);
512
+
513
+ localStorage.removeItem(`rootUrl.${rootUrl}`);
514
+
515
+ this.parentNode.remove();
516
+ };
517
+
518
+ const addRootUrlDom = (rootUrl, liAddNew) => {
519
+ const li = document.createElement('li');
520
+ if (rootUrl == window.docs.info.rootUrl) li.className = 'origin';
521
+ const span = document.createElement('span');
522
+ span.innerText = rootUrl;
523
+ if (rootUrl == selected) span.className = 'selected';
524
+ li.appendChild(span);
525
+ const label = document.createElement('label');
526
+ label.className = 'delete';
527
+ label.title = 'Xóa';
528
+ li.appendChild(label);
529
+ domRootUrls.insertBefore(li, liAddNew);
530
+ span.onclick = onspanclick;
531
+ label.onclick = onlabelclick;
532
+ };
533
+
534
+ const li = document.createElement('li');
535
+ const span = document.createElement('span');
536
+ span.innerText = 'Thêm mới API root url';
537
+ span.className = 'add-new';
538
+ li.appendChild(span);
539
+ domRootUrls.appendChild(li);
540
+
541
+ rootUrls.forEach((rootUrl) => addRootUrlDom(rootUrl, li));
542
+ span.onclick = () => {
543
+ const newRootUrl = prompt('Nhập API root url mới:');
544
+ if (!newRootUrl) return;
545
+ if (rootUrls.includes(newRootUrl)) return;
546
+
547
+ if (!newRootUrl.match(/^(https?:)?\/\//i)) {
548
+ alert('API root url không hợp lệ!');
549
+ return;
550
+ }
551
+
552
+ rootUrls.push(newRootUrl);
553
+ localStorage[`rootUrl.${newRootUrl}`] = '';
554
+ addRootUrlDom(newRootUrl, li);
555
+ };
556
+ }
557
+
558
+ function renderEnvironmentVariables() {
559
+ document.querySelector('#extension-env-vars').innerHTML = renderTemplate('template-project-environmentVariables');
560
+ if (!window.docs.environmentVariables) return;
561
+ const keys = Object.keys(window.docs.environmentVariables);
562
+ if (!keys.length) return;
563
+
564
+ document.querySelector('#extension-env-vars-custom').innerHTML = keys
565
+ .map((name) =>
566
+ renderTemplate('template-project-environmentVariables-custom', {
567
+ name,
568
+ description: window.docs.environmentVariables[name].description,
569
+ type: window.docs.environmentVariables[name].type,
570
+ }),
571
+ )
572
+ .join('');
573
+ }
574
+
575
+ function renderExtensionAuth() {
576
+ if (!window.docs.features?.includes('auth')) return;
577
+ document.querySelector('#extension-auth').innerHTML = renderTemplate('template-extension-DefaultAuth-module', {
578
+ rootUrl: localStorage.selected_root_url,
579
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
580
+ domain: getApiDomain(localStorage.selected_root_url),
581
+ });
582
+ }
583
+
584
+ function renderExtensionFile() {
585
+ if (!window.docs.features?.includes('file')) return;
586
+ document.querySelector('#extension-file').innerHTML = renderTemplate('template-extension-File-module', {
587
+ rootUrl: localStorage.selected_root_url,
588
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
589
+ domain: getApiDomain(localStorage.selected_root_url),
590
+ });
591
+ }
592
+
593
+ function renderExtensionMail() {
594
+ if (!window.docs.features?.includes('mail')) return;
595
+ document.querySelector('#extension-mailing').innerHTML = renderTemplate('template-extension-Mailing-module', {
596
+ rootUrl: localStorage.selected_root_url,
597
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
598
+ domain: getApiDomain(localStorage.selected_root_url),
599
+ });
600
+ }
601
+
602
+ function renderClientDrivers() {
603
+ if (!window.docs.features?.includes('driver')) return;
604
+ document.querySelector('#extension-client-drivers').innerHTML = renderTemplate('template-client-drivers');
605
+ }
606
+
607
+ function renderEntities() {
608
+ if (!window.docs.entities || typeof window.docs.entities !== 'object') return;
609
+ document.querySelector('#project-entities').innerHTML = Object.values(window.docs.entities)
610
+ .map((entity) => renderTemplate('template-project-entity', entity))
611
+ .join('');
612
+ }
613
+
614
+ function renderEntity(entityName) {
615
+ if (this.dataset.rendered) return;
616
+ this.dataset.rendered = true;
617
+ const entity = window.docs.entities[entityName];
618
+ if (!entity) return;
619
+ if (entity.actions && typeof entity.actions === 'object') {
620
+ const dom = this.parentNode.querySelector('.project-entity-actions');
621
+ dom.innerHTML = Object.keys(entity.actions)
622
+ .map((actionName) =>
623
+ renderTemplate('template-project-entity-actions', {
624
+ entityName: entity.name,
625
+ actionName,
626
+ className: getPanelClass(actionName),
627
+ actionHttpMethod: getHttpMethod(actionName),
628
+ actionApiUrl: getApiUrl(actionName, localStorage.selected_root_url, entity.name),
629
+ actionDescription: getDescriptionByActionName(actionName, entity.name),
630
+ }),
631
+ )
632
+ .join('');
633
+ initDom(dom);
634
+ }
635
+
636
+ if (entity.views && typeof entity.views === 'object') {
637
+ const dom = this.parentNode.querySelector('.project-entity-views');
638
+ dom.innerHTML = Object.keys(entity.views)
639
+ .map((viewName) =>
640
+ renderTemplate('template-project-entity-views', {
641
+ entityName: entity.name,
642
+ viewName,
643
+ actionApiUrl: getApiViewUrl(localStorage.selected_root_url, entity.name, viewName),
644
+ description: entity.views[viewName]?.[0]?.description ?? '',
645
+ }),
646
+ )
647
+ .join('');
648
+ initDom(dom);
649
+ }
650
+ }
651
+
652
+ function renderEntityAction(entityName, actionName) {
653
+ if (this.dataset.rendered) return;
654
+ this.dataset.rendered = true;
655
+
656
+ const entity = window.docs.entities[entityName];
657
+ const actionRoles = entity.actions[actionName];
658
+
659
+ const navTabs = this.parentNode.querySelector('.nav-tabs');
660
+
661
+ navTabs.innerHTML = actionRoles
662
+ .map((actionRole) =>
663
+ renderTemplate('template-project-entity-action-role', {
664
+ explainedRole: explainRoles(actionRole.grant),
665
+ entityName,
666
+ actionName,
667
+ grant: actionRole.grant,
668
+ }),
669
+ )
670
+ .join('');
671
+
672
+ initDom(navTabs);
673
+
674
+ activeFirstChild.call(navTabs);
675
+ }
676
+
677
+ function renderEntityActionRolePage(entityName, actionName, grant) {
678
+ if (this.dataset.rendered) return;
679
+ this.dataset.rendered = true;
680
+
681
+ const entity = window.docs.entities[entityName];
682
+ const action = entity.actions[actionName].find((a) => a.grant === grant);
683
+
684
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector('.tab-pages');
685
+ tabPages.innerHTML += renderTemplate('template-project-entity-action-page', { grant });
686
+
687
+ let template;
688
+ let callback;
689
+ let codeSnippetName = actionName;
690
+ switch (actionName) {
691
+ case 'findMany':
692
+ template = 'template-findMany';
693
+ callback = renderFindMany;
694
+ break;
695
+ case 'findById':
696
+ template = 'template-findById';
697
+ callback = renderFindById;
698
+ break;
699
+ case 'createOne':
700
+ template = 'template-createOne';
701
+ callback = renderCreateOne;
702
+ break;
703
+ case 'createMany':
704
+ template = 'template-createMany';
705
+ callback = renderCreateMany;
706
+ break;
707
+ case 'updateOne':
708
+ template = 'template-updateOne';
709
+ callback = renderUpdateOne;
710
+ break;
711
+ case 'updateMany':
712
+ template = 'template-updateMany';
713
+ callback = renderUpdateMany;
714
+ break;
715
+ case 'updatePartially':
716
+ template = 'template-updatePartially';
717
+ callback = renderUpdatePartially;
718
+ break;
719
+ case 'deleteOne':
720
+ template = 'template-deleteOne';
721
+ callback = renderDeleteOne;
722
+ break;
723
+ case 'deleteMany':
724
+ template = 'template-deleteMany';
725
+ callback = renderDeleteMany;
726
+ break;
727
+ default:
728
+ template = 'template-generalAction';
729
+ callback = renderGeneralAction;
730
+ codeSnippetName = 'generalAction';
731
+ break;
732
+ }
733
+ const tabPage = Array.prototype.find.call(
734
+ tabPages.querySelectorAll('.tab-page'),
735
+ (dom) => dom.dataset?.role == action.grant,
736
+ );
737
+ if (!tabPage) return;
738
+ const args = {
739
+ tabPage,
740
+ action,
741
+ actionName,
742
+ entity,
743
+ entityName,
744
+ EntityName: toCSharpName(entityName),
745
+ domain: getApiDomain(localStorage.selected_root_url),
746
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
747
+ };
748
+ const snippet = window.codeSnippets[codeSnippetName] ?? {};
749
+ const data = {
750
+ explainedDenyRoles: explainRoles(action.deny),
751
+ entityName,
752
+ codeSnippetTabHeaders: Object.keys(snippet)
753
+ .map(
754
+ (lang, idx) =>
755
+ `<li role="presentation" ${idx ? '' : 'class="active"'}><a data-role="${lang}" onclick="activeRoleTab.call(this)">${lang}</a></li>`,
756
+ )
757
+ .join(''),
758
+ codeSnippetTabPages: Object.keys(snippet)
759
+ .map(
760
+ (lang, idx) =>
761
+ `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`,
762
+ )
763
+ .join(''),
764
+ EntityName: args.EntityName,
765
+ domain: args.domain,
766
+ rootUrlPath: args.rootUrlPath,
767
+ description: action.description,
768
+ };
769
+ tabPage.innerHTML =
770
+ renderTemplate(template, data) + renderTemplate('template-project-entity-action-page-codeSnippets', data);
771
+ initDom(tabPage);
772
+ if (!action.deny) tabPage.querySelector('.deny-roles')?.remove();
773
+
774
+ if (!action.matches || !Array.isArray(action.matches) || !action.matches.length)
775
+ tabPage.querySelector('.matches')?.remove();
776
+ else {
777
+ if (action.matches.length === 1) {
778
+ tabPage.querySelector('.matches .matches-length-gt-1')?.remove();
779
+ }
780
+ const dom = tabPage.querySelector('.matches .match-conditions');
781
+ if (dom) {
782
+ dom.innerHTML = action.matches.map((m) => renderTemplate('template-li-code', { value: m })).join('');
783
+ }
784
+ }
785
+ if (!action.description) {
786
+ tabPage.querySelector('.description')?.remove();
787
+ }
788
+ callback(args);
789
+ }
790
+
791
+ function renderFindMany(args) {
792
+ if (Array.isArray(args.action.returnableFields)) {
793
+ args.tabPage.querySelector('.output-without-fields').innerHTML = getModelOutput(
794
+ args.action.defaultFields,
795
+ args.entity.fields,
796
+ );
797
+ args.tabPage.querySelector('.field-list').innerHTML = args.action.returnableFields
798
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
799
+ .join('');
800
+ args.tabPage.querySelector('.output-with-fields').innerHTML = getModelOutput(
801
+ args.action.returnableFields,
802
+ args.entity.fields,
803
+ );
804
+ }
805
+
806
+ if (
807
+ !args.action.defaultFilters &&
808
+ !args.action.allowFilteringFields &&
809
+ !args.action.requiredFilteringFields &&
810
+ !args.entity.features?.vn_text?.fields?.length
811
+ ) {
812
+ args.tabPage.querySelector('.filters')?.remove();
813
+ } else {
814
+ if (Array.isArray(args.action.defaultFilters) && args.action.defaultFilters.length) {
815
+ if (args.action.defaultFilters.length === 1) args.tabPage.querySelector('.defaultFilters-length-gt-1')?.remove();
816
+ args.tabPage.querySelector('.defaultFilters-ul').innerHTML = args.action.defaultFilters
817
+ .map((filter) => renderTemplate('template-li-code', { value: filter }))
818
+ .join('');
819
+ } else {
820
+ args.tabPage.querySelector('.defaultFilters')?.remove();
821
+ }
822
+
823
+ if (Array.isArray(args.action.allowFilteringFields) && args.action.allowFilteringFields.length) {
824
+ args.tabPage.querySelector('.allowFilteringFields-list').innerHTML = args.action.allowFilteringFields
825
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
826
+ .join(' ');
827
+ } else {
828
+ args.tabPage.querySelector('.allowFilteringFields')?.remove();
829
+ }
830
+
831
+ if (Array.isArray(args.action.requiredFilteringFields) && args.action.requiredFilteringFields.length) {
832
+ args.tabPage.querySelector('.requiredFilteringFields-list').innerHTML = args.action.requiredFilteringFields
833
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
834
+ .join(' ');
835
+ } else {
836
+ args.tabPage.querySelector('.requiredFilteringFields')?.remove();
837
+ }
838
+
839
+ if (args.entity.features?.vn_text?.fields?.length) {
840
+ args.tabPage.querySelector('.features-vn_text-fields-channel-default-fields').innerHTML =
841
+ args.entity.features.vn_text.fields
842
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
843
+ .join(' ');
844
+
845
+ if (args.entity.features?.vn_text?.channels?.length) {
846
+ args.tabPage.querySelector('.features-vn_text-channels-list').innerHTML = args.entity.features.vn_text.channels
847
+ .map((channel) =>
848
+ renderTemplate('template-findMany-vn_text-channel', {
849
+ name: channel.name,
850
+ htmlFields: channel.fields
851
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
852
+ .join(' '),
853
+ }),
854
+ )
855
+ .join('');
856
+ }
857
+ } else {
858
+ args.tabPage.querySelector('.features-vn_text-fields')?.remove();
859
+ }
860
+ }
861
+
862
+ if (!args.action.allowSortings && !args.action.defaultSortings) {
863
+ args.tabPage.querySelector('.sort')?.remove();
864
+ } else {
865
+ if (Array.isArray(args.action.allowSortings) && args.action.allowSortings.length) {
866
+ args.tabPage.querySelector('.allowSortings-fields').innerHTML = args.action.allowSortings
867
+ .map((item) =>
868
+ renderTemplate('template-findMany-sorting', {
869
+ field: item.field,
870
+ sortType:
871
+ item.type === 'Both'
872
+ ? 'Cả TĂNG dần và GIẢM dần'
873
+ : item.type === 'Asc'
874
+ ? 'Chỉ TĂNG dần'
875
+ : item.type === 'Desc'
876
+ ? 'Chỉ GIẢM dần'
877
+ : item.type === undefined || item.type === null
878
+ ? 'Chỉ TĂNG dần'
879
+ : '',
880
+ }),
881
+ )
882
+ .join('');
883
+ } else {
884
+ args.tabPage.querySelector('.defaultFilters')?.remove();
885
+ }
886
+
887
+ if (Array.isArray(args.action.defaultSortings) && args.action.defaultSortings.length) {
888
+ args.tabPage.querySelector('.defaultSortings-fields').innerHTML = args.action.defaultSortings
889
+ .map((item) =>
890
+ renderTemplate('template-findMany-sorting', {
891
+ field: item.field,
892
+ sortType:
893
+ item.type === 'Asc'
894
+ ? 'TĂNG dần'
895
+ : item.type === 'Desc'
896
+ ? 'GIẢM dần'
897
+ : item.type === undefined || item.type === null
898
+ ? 'TĂNG dần'
899
+ : '',
900
+ }),
901
+ )
902
+ .join('');
903
+ } else {
904
+ args.tabPage.querySelector('.defaultSortings')?.remove();
905
+ }
906
+ }
907
+
908
+ args.tabPage.querySelector('.paging').innerHTML = renderTemplate('template-findMany-paging', {
909
+ strPagingType:
910
+ args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === 'None'
911
+ ? 'Không phân trang'
912
+ : args.action.pagingType === 'LimitOffset'
913
+ ? 'Theo limit, offset'
914
+ : args.action.pagingType === 'Page'
915
+ ? 'Theo page number'
916
+ : '',
917
+ entityName: args.entityName,
918
+ maxPageSize: args.action.maxPageSize,
919
+ maxRecordCount:
920
+ args.action.maxPageSize === undefined || args.action.maxPageSize === null
921
+ ? (args.action.pageSize ?? 25)
922
+ : Math.min(args.action.maxPageSize, args.action.pageSize ?? 25),
923
+ });
924
+
925
+ if (args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === 'None') {
926
+ args.tabPage.querySelector('.pagingType-ne-None')?.remove();
927
+ } else if (args.action.maxPageSize === undefined || args.action.maxPageSize === null) {
928
+ args.tabPage.querySelector('.maxPageSize')?.remove();
929
+ }
930
+
931
+ if (args.action.includeTotal !== true) {
932
+ args.tabPage.querySelector('.includeTotal')?.remove();
933
+ }
934
+
935
+ if (args.action.cache?.enable !== true) {
936
+ args.tabPage.querySelector('.cache')?.remove();
937
+ } else {
938
+ args.tabPage.querySelector('.cache').innerHTML = renderTemplate('template-findMany-cache', {
939
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
940
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy),
941
+ });
942
+ }
943
+ }
944
+
945
+ function renderFindById(args) {
946
+ if (Array.isArray(args.action.returnableFields)) {
947
+ args.tabPage.querySelector('.output-without-fields').innerHTML = getModelOutput(
948
+ args.action.defaultFields,
949
+ args.entity.fields,
950
+ );
951
+ args.tabPage.querySelector('.field-list').innerHTML = args.action.returnableFields
952
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
953
+ .join('');
954
+ args.tabPage.querySelector('.output-with-fields').innerHTML = getModelOutput(
955
+ args.action.returnableFields,
956
+ args.entity.fields,
957
+ );
958
+ }
959
+
960
+ if (args.action.cache?.enable !== true) {
961
+ args.tabPage.querySelector('.cache')?.remove();
962
+ } else {
963
+ args.tabPage.querySelector('.cache').innerHTML = renderTemplate('template-findMany-cache', {
964
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
965
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy),
966
+ });
967
+ }
968
+ }
969
+
970
+ function renderCreateOne(args) {
971
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
972
+ excludeId: true,
973
+ showDefaultValue: true,
974
+ });
975
+ }
976
+
977
+ function renderCreateMany(args) {
978
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
979
+ excludeId: true,
980
+ showDefaultValue: true,
981
+ });
982
+ }
983
+
984
+ function renderUpdateOne(args) {
985
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
986
+ showDefaultValue: true,
987
+ });
988
+ }
989
+
990
+ function renderUpdateMany(args) {
991
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
992
+ showDefaultValue: true,
993
+ });
994
+ }
995
+
996
+ function renderUpdatePartially(args) {
997
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
998
+ optionalToAll: true,
999
+ });
1000
+ }
1001
+
1002
+ function renderDeleteOne(args) {}
1003
+
1004
+ function renderDeleteMany(args) {}
1005
+
1006
+ function renderGeneralAction(args) {
1007
+ if (args.action?.codeHint?.delegator?.param?.fields) {
1008
+ args.tabPage.querySelector('.query-string-model').innerHTML = formatHintModel(
1009
+ args.action.codeHint.delegator.param.fields,
1010
+ ).trim();
1011
+ } else {
1012
+ args.tabPage.querySelector('.query-string')?.remove();
1013
+ }
1014
+ if (args.action?.codeHint?.delegator?.requestBody?.fields) {
1015
+ args.tabPage.querySelector('.request-body-model').innerHTML = formatHintModel(
1016
+ args.action.codeHint.delegator.requestBody.fields,
1017
+ ).trim();
1018
+ } else if (args.action?.codeHint?.delegator?.requestBody?.items?.fields) {
1019
+ args.tabPage.querySelector('.request-body-model').innerHTML = 'ARRAY OF:\n' + formatHintModel(
1020
+ args.action.codeHint.delegator.requestBody.items.fields,
1021
+ ).trim();
1022
+ } else {
1023
+ args.tabPage.querySelector('.request-body')?.remove();
1024
+ }
1025
+ console.log('args.action.codeHint.delegator', args.action.codeHint.delegator);
1026
+ if (args.action?.codeHint?.delegator?.result?.fields) {
1027
+ args.tabPage.querySelector('.response-body-model').innerHTML = formatHintModel(
1028
+ args.action.codeHint.delegator.result.fields,
1029
+ ).trim();
1030
+ } else if (args.action?.codeHint?.delegator?.result?.items?.fields) {
1031
+ args.tabPage.querySelector('.response-body-model').innerHTML = 'ARRAY OF:\n' + formatHintModel(
1032
+ args.action.codeHint.delegator.result.items.fields,
1033
+ ).trim();
1034
+ } else {
1035
+ args.tabPage.querySelector('.response-body')?.remove();
1036
+ }
1037
+ }
1038
+
1039
+ function renderEntityView(entityName, viewName) {
1040
+ if (this.dataset.rendered) return;
1041
+ this.dataset.rendered = true;
1042
+
1043
+ const entity = window.docs.entities[entityName];
1044
+ const viewRoles = entity.views[viewName];
1045
+
1046
+ const navTabs = this.parentNode.querySelector('.nav-tabs');
1047
+
1048
+ navTabs.innerHTML = viewRoles
1049
+ .map((viewRole) =>
1050
+ renderTemplate('template-project-entity-view-role', {
1051
+ explainedRole: explainRoles(viewRole.grant),
1052
+ entityName,
1053
+ viewName,
1054
+ grant: viewRole.grant,
1055
+ }),
1056
+ )
1057
+ .join('');
1058
+ initDom(navTabs);
1059
+ activeFirstChild.call(navTabs);
1060
+ }
1061
+
1062
+ function renderEntityViewRolePage(entityName, viewName, grant) {
1063
+ if (this.dataset.rendered) return;
1064
+ this.dataset.rendered = true;
1065
+
1066
+ const entity = window.docs.entities[entityName];
1067
+ const view = entity.views[viewName].find((a) => a.grant === grant);
1068
+
1069
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector('.tab-pages');
1070
+ tabPages.innerHTML += renderTemplate('template-project-entity-view-page', { grant });
1071
+
1072
+ const tabPage = Array.prototype.find.call(
1073
+ tabPages.querySelectorAll('.tab-page'),
1074
+ (dom) => dom.dataset?.role == view.grant,
1075
+ );
1076
+ if (!tabPage) return;
1077
+ const args = {
1078
+ tabPage,
1079
+ view,
1080
+ viewName,
1081
+ entity,
1082
+ entityName,
1083
+ EntityName: toCSharpName(entityName),
1084
+ domain: getApiDomain(localStorage.selected_root_url),
1085
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
1086
+ };
1087
+ const snippet = window.codeSnippets.view;
1088
+ const data = {
1089
+ explainedDenyRoles: explainRoles(view.deny),
1090
+ entityName,
1091
+ viewName,
1092
+ codeSnippetTabHeaders: Object.keys(snippet)
1093
+ .map(
1094
+ (lang, idx) =>
1095
+ `<li role="presentation" ${idx ? '' : 'class="active"'}><a data-role="${lang}" onclick="activeRoleTab.call(this)">${lang}</a></li>`,
1096
+ )
1097
+ .join(''),
1098
+ codeSnippetTabPages: Object.keys(snippet)
1099
+ .map(
1100
+ (lang, idx) =>
1101
+ `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`,
1102
+ )
1103
+ .join(''),
1104
+ description: view.description,
1105
+ outputModel: formatHintModel(view.codeHint?.output?.fields),
1106
+ outputEmptyResult: JSON.stringify(view.emptyResult, null, 4),
1107
+ };
1108
+ tabPage.innerHTML =
1109
+ renderTemplate('template-view', data) + renderTemplate('template-project-entity-view-page-codeSnippets', data);
1110
+ initDom(tabPage);
1111
+ if (!view.deny) tabPage.querySelector('.deny-roles')?.remove();
1112
+
1113
+ if (!Array.isArray(view.parameters) || !view.parameters.length) {
1114
+ tabPage.querySelector('.parameters-input-pane')?.remove();
1115
+ } else {
1116
+ tabPage.querySelector('.parameters-list').innerHTML = view.parameters
1117
+ .map((p) =>
1118
+ renderTemplate('template-view-parameters', {
1119
+ field: p.field,
1120
+ type: (p.isArray ? 'array of ' : '') + (p.type ?? 'string'),
1121
+ description: p.description ?? '',
1122
+ defaultValue: p.defaultValue ? `, default (${p.defaultValue})` : '',
1123
+ required: p.required ? 'required' : 'optional',
1124
+ }),
1125
+ )
1126
+ .join('');
1127
+ }
1128
+ if (!view.codeHint?.output?.fields) {
1129
+ tabPage.querySelector('.output-model')?.remove();
1130
+ }
1131
+ if (!view.emptyResult) {
1132
+ tabPage.querySelector('.output-epmty-result')?.remove();
1133
+ }
1134
+ if (!view.codeHint?.output?.fields && !view.emptyResult) {
1135
+ tabPage.querySelector('.output-pane')?.remove();
1136
+ }
1137
+
1138
+ if (!view.description) {
1139
+ tabPage.querySelector('.description')?.remove();
1140
+ }
1141
+ //callback(args);
1142
+ }
1143
+
1144
+ window.codeSnippets = {
1145
+ findMany: {
1146
+ Javascript: (args) =>
1147
+ renderTemplate('template-codeSnippets-findMany-Javascript', {
1148
+ entityName: args.entityName,
1149
+ allowPagingDisplay: args.action.pagingType && args.action.pagingType != 'None' ? 'inline' : 'none',
1150
+ includeTotalDisplay: args.action.includeTotal ? 'inline' : 'none',
1151
+ fields: args.action.returnableFields
1152
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1153
+ .join(''),
1154
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1155
+ sortFields: args.action.allowSortings
1156
+ ?.map(
1157
+ (sort) =>
1158
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1159
+ )
1160
+ .join(''),
1161
+ limitDisplay: args.action.pagingType === 'LimitOffset' || args.action.pagingType === 'Page' ? 'inline' : 'none',
1162
+ offsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1163
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1164
+ vnTextDisplay: args.entity.features?.vn_text?.fields?.length ? 'inline' : 'none',
1165
+ vnTextFields: args.entity.features?.vn_text?.fields
1166
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1167
+ .join(''),
1168
+ countAsyncDisplay: args.action.includeTotal ? 'inline' : 'none',
1169
+ }),
1170
+ JavascriptModel: (args) =>
1171
+ renderTemplate('template-codeSnippets-findMany-JavascriptModel', {
1172
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_undefined' }),
1173
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model' }),
1174
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_null' }),
1175
+ }),
1176
+ CSharp: (args) =>
1177
+ renderTemplate('template-codeSnippets-findMany-CSharp', {
1178
+ entityName: args.entityName,
1179
+ EntityName: args.EntityName,
1180
+ fields: args.action.returnableFields
1181
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1182
+ .join(''),
1183
+ sortFields: args.action.allowSortings
1184
+ ?.map(
1185
+ (sort) =>
1186
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1187
+ )
1188
+ .join(''),
1189
+ }),
1190
+ HTTP: (args) =>
1191
+ renderTemplate('template-codeSnippets-findMany-HTTP', {
1192
+ domain: args.domain,
1193
+ rootUrlPath: args.rootUrlPath,
1194
+ entityName: args.entityName,
1195
+ fields: args.action.returnableFields
1196
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1197
+ .join(''),
1198
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1199
+ sortFields: args.action.allowSortings
1200
+ ?.map(
1201
+ (sort) =>
1202
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1203
+ )
1204
+ .join(''),
1205
+ limitOffsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1206
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1207
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1208
+ }),
1209
+ cURL: (args) =>
1210
+ renderTemplate('template-codeSnippets-findMany-cURL', {
1211
+ rootUrl: localStorage.selected_root_url,
1212
+ entityName: args.entityName,
1213
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1214
+ fields: args.action.returnableFields
1215
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1216
+ .join(''),
1217
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1218
+ sortFields: args.action.allowSortings
1219
+ ?.map(
1220
+ (sort) =>
1221
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1222
+ )
1223
+ .join(''),
1224
+ limitOffsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1225
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1226
+ }),
1227
+ Java: (args) =>
1228
+ renderTemplate('template-codeSnippets-findMany-Java', {
1229
+ entityName: args.entityName,
1230
+ EntityName: args.EntityName,
1231
+ fields: args.action.returnableFields
1232
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1233
+ .join(''),
1234
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1235
+ sortFields: args.action.allowSortings
1236
+ ?.map(
1237
+ (sort) =>
1238
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1239
+ )
1240
+ .join(''),
1241
+ }),
1242
+ JavaAsync: (args) =>
1243
+ renderTemplate('template-codeSnippets-findMany-JavaAsync', {
1244
+ entityName: args.entityName,
1245
+ EntityName: args.EntityName,
1246
+ fields: args.action.returnableFields
1247
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1248
+ .join(''),
1249
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1250
+ sortFields: args.action.allowSortings
1251
+ ?.map(
1252
+ (sort) =>
1253
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1254
+ )
1255
+ .join(''),
1256
+ }),
1257
+ },
1258
+ findById: {
1259
+ Javascript: (args) =>
1260
+ renderTemplate('template-codeSnippets-findById-Javascript', {
1261
+ entityName: args.entityName,
1262
+ fields: args.action.returnableFields
1263
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1264
+ .join(''),
1265
+ }),
1266
+ JavascriptModel: (args) =>
1267
+ renderTemplate('template-codeSnippets-findById-JavascriptModel', {
1268
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_undefined' }),
1269
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model' }),
1270
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_null' }),
1271
+ }),
1272
+ CSharp: (args) =>
1273
+ renderTemplate('template-codeSnippets-findById-CSharp', {
1274
+ entityName: args.entityName,
1275
+ EntityName: args.EntityName,
1276
+ fields: args.action.returnableFields
1277
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1278
+ .join(''),
1279
+ }),
1280
+ HTTP: (args) =>
1281
+ renderTemplate('template-codeSnippets-findById-HTTP', {
1282
+ domain: args.domain,
1283
+ rootUrlPath: args.rootUrlPath,
1284
+ entityName: args.entityName,
1285
+ fields: args.action.returnableFields
1286
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1287
+ .join(''),
1288
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1289
+ }),
1290
+ cURL: (args) =>
1291
+ renderTemplate('template-codeSnippets-findById-cURL', {
1292
+ rootUrl: localStorage.selected_root_url,
1293
+ entityName: args.entityName,
1294
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1295
+ fields: args.action.returnableFields
1296
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1297
+ .join(''),
1298
+ }),
1299
+ Java: (args) =>
1300
+ renderTemplate('template-codeSnippets-findById-Java', {
1301
+ entityName: args.entityName,
1302
+ EntityName: args.EntityName,
1303
+ fields: args.action.returnableFields
1304
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1305
+ .join(''),
1306
+ }),
1307
+ JavaAsync: (args) =>
1308
+ renderTemplate('template-codeSnippets-findById-JavaAsync', {
1309
+ entityName: args.entityName,
1310
+ EntityName: args.EntityName,
1311
+ fields: args.action.returnableFields
1312
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1313
+ .join(''),
1314
+ }),
1315
+ },
1316
+ createOne: {
1317
+ Javascript: (args) =>
1318
+ renderTemplate('template-codeSnippets-createOne-Javascript', {
1319
+ entityName: args.entityName,
1320
+ }),
1321
+ JavascriptModel: (args) =>
1322
+ renderTemplate('template-codeSnippets-createOne-JavascriptModel', {
1323
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1324
+ mode: 'model_undefined',
1325
+ excludeId: true,
1326
+ }),
1327
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', excludeId: true }),
1328
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', excludeId: true }),
1329
+ }),
1330
+ CSharp: (args) =>
1331
+ renderTemplate('template-codeSnippets-createOne-CSharp', {
1332
+ entityName: args.entityName,
1333
+ EntityName: args.EntityName,
1334
+ }),
1335
+ HTTP: (args) =>
1336
+ renderTemplate('template-codeSnippets-createOne-HTTP', {
1337
+ domain: args.domain,
1338
+ rootUrlPath: args.rootUrlPath,
1339
+ entityName: args.entityName,
1340
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1341
+ }),
1342
+ cURL: (args) =>
1343
+ renderTemplate('template-codeSnippets-createOne-cURL', {
1344
+ rootUrl: localStorage.selected_root_url,
1345
+ entityName: args.entityName,
1346
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1347
+ }),
1348
+ Java: (args) =>
1349
+ renderTemplate('template-codeSnippets-createOne-Java', {
1350
+ entityName: args.entityName,
1351
+ EntityName: args.EntityName,
1352
+ }),
1353
+ JavaAsync: (args) =>
1354
+ renderTemplate('template-codeSnippets-createOne-JavaAsync', {
1355
+ entityName: args.entityName,
1356
+ EntityName: args.EntityName,
1357
+ }),
1358
+ },
1359
+ createMany: {
1360
+ Javascript: (args) =>
1361
+ renderTemplate('template-codeSnippets-createMany-Javascript', {
1362
+ entityName: args.entityName,
1363
+ }),
1364
+ JavascriptModel: (args) =>
1365
+ renderTemplate('template-codeSnippets-createMany-JavascriptModel', {
1366
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1367
+ mode: 'model_undefined',
1368
+ excludeId: true,
1369
+ }),
1370
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', excludeId: true }),
1371
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', excludeId: true }),
1372
+ }),
1373
+ CSharp: (args) =>
1374
+ renderTemplate('template-codeSnippets-createMany-CSharp', {
1375
+ entityName: args.entityName,
1376
+ EntityName: args.EntityName,
1377
+ }),
1378
+ HTTP: (args) =>
1379
+ renderTemplate('template-codeSnippets-createMany-HTTP', {
1380
+ domain: args.domain,
1381
+ rootUrlPath: args.rootUrlPath,
1382
+ entityName: args.entityName,
1383
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1384
+ }),
1385
+ cURL: (args) =>
1386
+ renderTemplate('template-codeSnippets-createMany-cURL', {
1387
+ rootUrl: localStorage.selected_root_url,
1388
+ entityName: args.entityName,
1389
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1390
+ }),
1391
+ Java: (args) =>
1392
+ renderTemplate('template-codeSnippets-createMany-Java', {
1393
+ entityName: args.entityName,
1394
+ EntityName: args.EntityName,
1395
+ }),
1396
+ JavaAsync: (args) =>
1397
+ renderTemplate('template-codeSnippets-createMany-JavaAsync', {
1398
+ entityName: args.entityName,
1399
+ EntityName: args.EntityName,
1400
+ }),
1401
+ },
1402
+ updateOne: {
1403
+ Javascript: (args) =>
1404
+ renderTemplate('template-codeSnippets-updateOne-Javascript', {
1405
+ entityName: args.entityName,
1406
+ }),
1407
+ JavascriptModel: (args) =>
1408
+ renderTemplate('template-codeSnippets-updateOne-JavascriptModel', {
1409
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_undefined' }),
1410
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model' }),
1411
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null' }),
1412
+ }),
1413
+ CSharp: (args) =>
1414
+ renderTemplate('template-codeSnippets-updateOne-CSharp', {
1415
+ entityName: args.entityName,
1416
+ EntityName: args.EntityName,
1417
+ }),
1418
+ HTTP: (args) =>
1419
+ renderTemplate('template-codeSnippets-updateOne-HTTP', {
1420
+ domain: args.domain,
1421
+ rootUrlPath: args.rootUrlPath,
1422
+ entityName: args.entityName,
1423
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1424
+ }),
1425
+ cURL: (args) =>
1426
+ renderTemplate('template-codeSnippets-updateOne-cURL', {
1427
+ rootUrl: localStorage.selected_root_url,
1428
+ entityName: args.entityName,
1429
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1430
+ }),
1431
+ Java: (args) =>
1432
+ renderTemplate('template-codeSnippets-updateOne-Java', {
1433
+ entityName: args.entityName,
1434
+ EntityName: args.EntityName,
1435
+ }),
1436
+ JavaAsync: (args) =>
1437
+ renderTemplate('template-codeSnippets-updateOne-JavaAsync', {
1438
+ entityName: args.entityName,
1439
+ EntityName: args.EntityName,
1440
+ }),
1441
+ },
1442
+ updateMany: {
1443
+ Javascript: (args) =>
1444
+ renderTemplate('template-codeSnippets-updateMany-Javascript', {
1445
+ entityName: args.entityName,
1446
+ }),
1447
+ JavascriptModel: (args) =>
1448
+ renderTemplate('template-codeSnippets-updateMany-JavascriptModel', {
1449
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_undefined' }),
1450
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model' }),
1451
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null' }),
1452
+ }),
1453
+ CSharp: (args) =>
1454
+ renderTemplate('template-codeSnippets-updateMany-CSharp', {
1455
+ entityName: args.entityName,
1456
+ EntityName: args.EntityName,
1457
+ }),
1458
+ HTTP: (args) =>
1459
+ renderTemplate('template-codeSnippets-updateMany-HTTP', {
1460
+ domain: args.domain,
1461
+ rootUrlPath: args.rootUrlPath,
1462
+ entityName: args.entityName,
1463
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1464
+ }),
1465
+ cURL: (args) =>
1466
+ renderTemplate('template-codeSnippets-updateMany-cURL', {
1467
+ rootUrl: localStorage.selected_root_url,
1468
+ entityName: args.entityName,
1469
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1470
+ }),
1471
+ Java: (args) =>
1472
+ renderTemplate('template-codeSnippets-updateMany-Java', {
1473
+ entityName: args.entityName,
1474
+ EntityName: args.EntityName,
1475
+ }),
1476
+ JavaAsync: (args) =>
1477
+ renderTemplate('template-codeSnippets-updateMany-JavaAsync', {
1478
+ entityName: args.entityName,
1479
+ EntityName: args.EntityName,
1480
+ }),
1481
+ },
1482
+ updatePartially: {
1483
+ Javascript: (args) =>
1484
+ renderTemplate('template-codeSnippets-updatePartially-Javascript', {
1485
+ entityName: args.entityName,
1486
+ }),
1487
+ JavascriptModel: (args) =>
1488
+ renderTemplate('template-codeSnippets-updatePartially-JavascriptModel', {
1489
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1490
+ mode: 'model_undefined',
1491
+ optionalToAll: true,
1492
+ }),
1493
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', optionalToAll: true }),
1494
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', optionalToAll: true }),
1495
+ }),
1496
+ CSharp: (args) =>
1497
+ renderTemplate('template-codeSnippets-updatePartially-CSharp', {
1498
+ entityName: args.entityName,
1499
+ EntityName: args.EntityName,
1500
+ }),
1501
+ HTTP: (args) =>
1502
+ renderTemplate('template-codeSnippets-updatePartially-HTTP', {
1503
+ domain: args.domain,
1504
+ rootUrlPath: args.rootUrlPath,
1505
+ entityName: args.entityName,
1506
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1507
+ }),
1508
+ cURL: (args) =>
1509
+ renderTemplate('template-codeSnippets-updatePartially-cURL', {
1510
+ rootUrl: localStorage.selected_root_url,
1511
+ entityName: args.entityName,
1512
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1513
+ }),
1514
+ Java: (args) =>
1515
+ renderTemplate('template-codeSnippets-updatePartially-Java', {
1516
+ entityName: args.entityName,
1517
+ EntityName: args.EntityName,
1518
+ }),
1519
+ JavaAsync: (args) =>
1520
+ renderTemplate('template-codeSnippets-updatePartially-JavaAsync', {
1521
+ entityName: args.entityName,
1522
+ EntityName: args.EntityName,
1523
+ }),
1524
+ },
1525
+ deleteOne: {
1526
+ Javascript: (args) =>
1527
+ renderTemplate('template-codeSnippets-deleteOne-Javascript', {
1528
+ entityName: args.entityName,
1529
+ }),
1530
+ CSharp: (args) =>
1531
+ renderTemplate('template-codeSnippets-deleteOne-CSharp', {
1532
+ entityName: args.entityName,
1533
+ EntityName: args.EntityName,
1534
+ }),
1535
+ HTTP: (args) =>
1536
+ renderTemplate('template-codeSnippets-deleteOne-HTTP', {
1537
+ domain: args.domain,
1538
+ rootUrlPath: args.rootUrlPath,
1539
+ entityName: args.entityName,
1540
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1541
+ }),
1542
+ cURL: (args) =>
1543
+ renderTemplate('template-codeSnippets-deleteOne-cURL', {
1544
+ rootUrl: localStorage.selected_root_url,
1545
+ entityName: args.entityName,
1546
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1547
+ }),
1548
+ Java: (args) =>
1549
+ renderTemplate('template-codeSnippets-deleteOne-Java', {
1550
+ entityName: args.entityName,
1551
+ EntityName: args.EntityName,
1552
+ }),
1553
+ JavaAsync: (args) =>
1554
+ renderTemplate('template-codeSnippets-deleteOne-JavaAsync', {
1555
+ entityName: args.entityName,
1556
+ EntityName: args.EntityName,
1557
+ }),
1558
+ },
1559
+ deleteMany: {
1560
+ Javascript: (args) =>
1561
+ renderTemplate('template-codeSnippets-deleteMany-Javascript', {
1562
+ entityName: args.entityName,
1563
+ }),
1564
+ CSharp: (args) =>
1565
+ renderTemplate('template-codeSnippets-deleteMany-CSharp', {
1566
+ entityName: args.entityName,
1567
+ EntityName: args.EntityName,
1568
+ }),
1569
+ HTTP: (args) =>
1570
+ renderTemplate('template-codeSnippets-deleteMany-HTTP', {
1571
+ domain: args.domain,
1572
+ rootUrlPath: args.rootUrlPath,
1573
+ entityName: args.entityName,
1574
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1575
+ }),
1576
+ cURL: (args) =>
1577
+ renderTemplate('template-codeSnippets-deleteMany-cURL', {
1578
+ rootUrl: localStorage.selected_root_url,
1579
+ entityName: args.entityName,
1580
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1581
+ }),
1582
+ Java: (args) =>
1583
+ renderTemplate('template-codeSnippets-deleteMany-Java', {
1584
+ entityName: args.entityName,
1585
+ EntityName: args.EntityName,
1586
+ }),
1587
+ JavaAsync: (args) =>
1588
+ renderTemplate('template-codeSnippets-deleteMany-JavaAsync', {
1589
+ entityName: args.entityName,
1590
+ EntityName: args.EntityName,
1591
+ }),
1592
+ },
1593
+ generalAction: {
1594
+ Javascript: (args) =>
1595
+ renderTemplate('template-codeSnippets-generalAction-Javascript', {
1596
+ entityName: args.entityName,
1597
+ httpMethod: getHttpMethod(args.actionName),
1598
+ paramDisplay: args.action?.codeHint?.delegator?.param?.fields ? 'inline' : 'none',
1599
+ bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none',
1600
+ }),
1601
+ CSharp: (args) =>
1602
+ renderTemplate('template-codeSnippets-generalAction-CSharp', {
1603
+ entityName: args.entityName,
1604
+ EntityName: args.EntityName,
1605
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1606
+ }),
1607
+ HTTP: (args) =>
1608
+ renderTemplate('template-codeSnippets-generalAction-HTTP', {
1609
+ domain: args.domain,
1610
+ rootUrlPath: args.rootUrlPath,
1611
+ entityName: args.entityName,
1612
+ httpMethod: getHttpMethod(args.actionName),
1613
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1614
+ }),
1615
+ cURL: (args) =>
1616
+ renderTemplate('template-codeSnippets-generalAction-cURL', {
1617
+ rootUrl: localStorage.selected_root_url,
1618
+ entityName: args.entityName,
1619
+ httpMethod: getHttpMethod(args.actionName),
1620
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1621
+ }),
1622
+ Java: (args) =>
1623
+ renderTemplate('template-codeSnippets-generalAction-Java', {
1624
+ entityName: args.entityName,
1625
+ EntityName: args.EntityName,
1626
+ methodName: getHttpMethod(args.actionName),
1627
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1628
+ }),
1629
+ JavaAsync: (args) =>
1630
+ renderTemplate('template-codeSnippets-generalAction-JavaAsync', {
1631
+ entityName: args.entityName,
1632
+ EntityName: args.EntityName,
1633
+ methodName: getHttpMethod(args.actionName),
1634
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1635
+ }),
1636
+ },
1637
+ view: {
1638
+ Javascript: (args) =>
1639
+ renderTemplate('template-codeSnippets-view-Javascript', {
1640
+ entityName: args.entityName,
1641
+ viewName: args.viewName,
1642
+ parameters: args.view.parameters
1643
+ ? '{\n ' +
1644
+ args.view.parameters
1645
+ .map((p) => `${encodeHtml(p.field)}: <span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1646
+ .join(',\n ') +
1647
+ '\n }'
1648
+ : '',
1649
+ }),
1650
+ JavascriptModel: (args) =>
1651
+ args.view.codeHint?.output?.fields
1652
+ ? renderTemplate('template-codeSnippets-view-JavascriptModel', {
1653
+ undefinedModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model_undefined' }),
1654
+ valueModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model' }),
1655
+ nullModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model_null' }),
1656
+ })
1657
+ : '',
1658
+ CSharp: (args) =>
1659
+ renderTemplate('template-codeSnippets-view-CSharp', {
1660
+ entityName: args.entityName,
1661
+ EntityName: args.EntityName,
1662
+ grantDisplay: args.view.grant === '*' ? 'none' : 'inline',
1663
+ Grant: toCSharpName(args.view.grant),
1664
+ ViewName: toCSharpName(args.viewName),
1665
+ parameters: args.view.parameters
1666
+ ? args.view.parameters
1667
+ .map(
1668
+ (p) =>
1669
+ `${encodeHtml(toCSharpName(p.field))} = <span class="place-holder">value_of_${encodeHtml(p.field)}</span>`,
1670
+ )
1671
+ .join(',\n ')
1672
+ : '',
1673
+ }),
1674
+ HTTP: (args) =>
1675
+ renderTemplate('template-codeSnippets-view-HTTP', {
1676
+ domain: args.domain,
1677
+ rootUrlPath: args.rootUrlPath,
1678
+ entityName: args.entityName,
1679
+ viewName: args.viewName,
1680
+ tokenDisplay: args.view.grant !== '*' ? 'inline' : 'none',
1681
+ parameters: args.view.parameters
1682
+ ? '?' +
1683
+ args.view.parameters
1684
+ .map((p) => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1685
+ .join('&')
1686
+ : '',
1687
+ }),
1688
+ cURL: (args) =>
1689
+ renderTemplate('template-codeSnippets-view-cURL', {
1690
+ rootUrl: localStorage.selected_root_url,
1691
+ entityName: args.entityName,
1692
+ tokenDisplay: args.view.grant !== '*' ? 'inline' : 'none',
1693
+ parameters: args.view.parameters
1694
+ ? '?' +
1695
+ args.view.parameters
1696
+ .map((p) => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1697
+ .join('&')
1698
+ : '',
1699
+ }),
1700
+ Java: (args) =>
1701
+ renderTemplate('template-codeSnippets-view-Java', {
1702
+ entityName: args.entityName,
1703
+ EntityName: args.EntityName,
1704
+ viewName: args.viewName,
1705
+ ViewName: toCSharpName(args.viewName),
1706
+ parameters: args.view.parameters
1707
+ ? args.view.parameters
1708
+ .map(
1709
+ (p) =>
1710
+ `arg.set${encodeHtml(toCSharpName(p.field))}(<span class="place-holder">value_of_${encodeHtml(p.field)}</span>);`,
1711
+ )
1712
+ .join(',\n ')
1713
+ : '',
1714
+ }),
1715
+ JavaAsync: (args) =>
1716
+ renderTemplate('template-codeSnippets-view-JavaAsync', {
1717
+ entityName: args.entityName,
1718
+ EntityName: args.EntityName,
1719
+ viewName: args.viewName,
1720
+ ViewName: toCSharpName(args.viewName),
1721
+ parameters: args.view.parameters
1722
+ ? args.view.parameters
1723
+ .map(
1724
+ (p) =>
1725
+ `arg.set${encodeHtml(toCSharpName(p.field))}(<span class="place-holder">value_of_${encodeHtml(p.field)}</span>);`,
1726
+ )
1727
+ .join(',\n ')
1728
+ : '',
1729
+ }),
1730
+ },
1731
+ };
1732
+
1733
+ function toggleParentClass() {
1734
+ const clazz = $(this).data('toggledClass');
1735
+ $(this).parent().toggleClass(clazz);
1736
+ var hash = $(this).data('hash');
1737
+ if (hash) {
1738
+ location.hash = hash;
1739
+ }
1740
+ const computedStyle = getComputedStyle(this);
1741
+ let stickyTop = 0;
1742
+ if (computedStyle.position === 'sticky') {
1743
+ stickyTop = parseInt(computedStyle.top);
1744
+ if (isNaN(stickyTop)) stickyTop = 0;
1745
+ }
1746
+
1747
+ if (!$(this).parent().hasClass(clazz)) {
1748
+ const b = document.body; //IE 'quirks'
1749
+ let d = document.documentElement; //IE with doctype
1750
+ d = d.clientHeight ? d : b;
1751
+
1752
+ if (parseInt(d.scrollTop) > this.offsetTop - stickyTop) window.scrollTo(0, this.offsetTop - stickyTop);
1753
+ }
1754
+ }
1755
+
1756
+ function activeRoleTab() {
1757
+ var role = $(this).data('role');
1758
+ $(this).parent().parent().find('.active').removeClass('active');
1759
+ $(this).parent().addClass('active');
1760
+ $(this)
1761
+ .parent()
1762
+ .parent()
1763
+ .parent()
1764
+ .find('> .tab-pages > .tab-page')
1765
+ .removeClass('active')
1766
+ .filter(function () {
1767
+ return $(this).data('role') === role;
1768
+ })
1769
+ .addClass('active');
1770
+ }
1771
+
1772
+ function activeFirstChild() {
1773
+ let dom = this;
1774
+ dom = dom.children.length && dom.children[0];
1775
+ if (!dom) return;
1776
+ dom = dom.children.length && dom.children[0];
1777
+ if (!dom) return;
1778
+ dom.onclick && dom.onclick();
1779
+ }
1780
+
1781
+ function gotoHash() {
1782
+ if (!location.hash) return;
1783
+
1784
+ const m = location.hash.match(/^#(\$[\w-]+|\w+)(\.((views\.)?\w+))?$/);
1785
+ if (!m) return;
1786
+
1787
+ const cardSelector = m[1].charAt(0) === '$' ? '#extension-' + m[1].substring(1) : '#entity-' + m[1];
1788
+ let dom = document.querySelector(cardSelector);
1789
+ if (!dom) return;
1790
+
1791
+ let top = dom.offsetTop;
1792
+ dom = dom.firstElementChild;
1793
+ if (!dom) return;
1794
+ dom.onclick && dom.onclick();
1795
+ let computedStyle = getComputedStyle(dom);
1796
+ let stickyTop = 0;
1797
+ if (computedStyle.position === 'sticky') {
1798
+ stickyTop = parseInt(computedStyle.top);
1799
+ if (isNaN(stickyTop)) stickyTop = 0;
1800
+ }
1801
+ window.scrollTo(0, top - stickyTop);
1802
+
1803
+ if (!m[3]) return;
1804
+
1805
+ const panelSelector =
1806
+ m[1].charAt(0) === '$'
1807
+ ? '#extension-' + m[1].substring(1) + '-' + m[3].replace(/[.]/g, '-')
1808
+ : '#action-' + m[1] + '-' + m[3].replace(/[.]/g, '-');
1809
+ dom = document.querySelector(panelSelector);
1810
+ if (!dom) return;
1811
+
1812
+ top = dom.offsetTop;
1813
+ dom = dom.firstElementChild;
1814
+ if (!dom) return;
1815
+ dom.onclick && dom.onclick();
1816
+ computedStyle = getComputedStyle(dom);
1817
+ stickyTop = 0;
1818
+ if (computedStyle.position === 'sticky') {
1819
+ stickyTop = parseInt(computedStyle.top);
1820
+ if (isNaN(stickyTop)) stickyTop = 0;
1821
+ }
1822
+ window.scrollTo(0, top - stickyTop);
1823
+ }
1824
+
1825
+ function copied() {
1826
+ const dom = document.querySelector('#copied');
1827
+ if (!dom) return;
1828
+
1829
+ dom.classList.add('show');
1830
+ setTimeout(() => dom.classList.remove('show'), 1000);
1831
+ }
1832
+
1833
+ function initDom(dom) {
1834
+ $('pre[data-language]', dom).each(function () {
1835
+ const holder = document.createElement('div');
1836
+ holder.className = 'command-bar';
1837
+ const copyButton = document.createElement('a');
1838
+ copyButton.innerHTML = 'Copy';
1839
+ holder.appendChild(copyButton);
1840
+ $(this).prepend(holder);
1841
+ copyButton.onclick = function () {
1842
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1843
+ alert('Can not copy, please use https protocol!');
1844
+ return;
1845
+ }
1846
+ const pre = $(this).parent().parent();
1847
+ const commandBar = $(this).parent().detach();
1848
+ try {
1849
+ if (window.ClipboardItem) {
1850
+ const content = pre.text();
1851
+ const blob = new Blob([content], { type: 'text/plain' });
1852
+ const text = new ClipboardItem({ 'text/plain': blob });
1853
+ navigator.clipboard.write([text]);
1854
+ } else {
1855
+ if (document.body.createTextRange) {
1856
+ const range = document.body.createTextRange();
1857
+ range.moveToElementText(pre[0]);
1858
+ range.select();
1859
+ } else if (window.getSelection) {
1860
+ const selection = window.getSelection();
1861
+ const range = document.createRange();
1862
+ range.selectNodeContents(pre[0]);
1863
+ selection.removeAllRanges();
1864
+ selection.addRange(range);
1865
+ }
1866
+ document.execCommand('copy');
1867
+ }
1868
+ } finally {
1869
+ pre.prepend(commandBar);
1870
+ }
1871
+
1872
+ copied();
1873
+ };
1874
+ });
1875
+
1876
+ $('pre[data-language=json] .command-bar', dom).each(function () {
1877
+ const copyButton = document.createElement('a');
1878
+ copyButton.innerHTML = 'Copy (without comment)';
1879
+ $(this).prepend(copyButton);
1880
+ copyButton.onclick = function () {
1881
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1882
+ alert('Can not copy, please use https protocol!');
1883
+ return;
1884
+ }
1885
+ const pre = $(this).parent().parent();
1886
+ const commandBar = $(this).parent().detach();
1887
+ pre.find('.code-comment').each(function () {
1888
+ this.dataset.innerHTML = this.innerHTML;
1889
+ this.innerHTML = '';
1890
+ });
1891
+ try {
1892
+ if (window.ClipboardItem) {
1893
+ const content = pre.text();
1894
+ const blob = new Blob([content], { type: 'text/plain' });
1895
+ const text = new ClipboardItem({ 'text/plain': blob });
1896
+ navigator.clipboard.write([text]);
1897
+ } else {
1898
+ if (document.body.createTextRange) {
1899
+ const range = document.body.createTextRange();
1900
+ range.moveToElementText(pre[0]);
1901
+ range.select();
1902
+ } else if (window.getSelection) {
1903
+ const selection = window.getSelection();
1904
+ const range = document.createRange();
1905
+ range.selectNodeContents(pre[0]);
1906
+ selection.removeAllRanges();
1907
+ selection.addRange(range);
1908
+ }
1909
+ document.execCommand('copy');
1910
+ }
1911
+ } finally {
1912
+ pre.prepend(commandBar);
1913
+ pre.find('.code-comment').each(function () {
1914
+ this.innerHTML = this.dataset.innerHTML;
1915
+ delete this.dataset.innerHTML;
1916
+ });
1917
+ }
1918
+
1919
+ copied();
1920
+ };
1921
+ });
1922
+ }