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

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