mushroom-cli 1.1.0-alpha.13 → 1.1.0-alpha.16

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.
@@ -0,0 +1,174 @@
1
+ (function () {
2
+ var urls = {};
3
+ function loadFile(url, successCallback, errorCallback) {
4
+ if (url in urls) {
5
+ var args = urls[url];
6
+ args.cached = true;
7
+ setTimeout(successCallback, 1, args);
8
+ return;
9
+ }
10
+ var xhr = new XMLHttpRequest();
11
+ xhr.onreadystatechange = function () {
12
+ if (this.readyState !== 4)
13
+ return;
14
+ if (this.status < 200 || this.status >= 300) {
15
+ if (typeof this.debugMode === "function" && this.debugMode())
16
+ console.error("Unable to load: " + url);
17
+ return;
18
+ }
19
+ var args = { content: this.responseText };
20
+ urls[url] = args;
21
+ if (typeof successCallback === "function")
22
+ successCallback(args);
23
+ };
24
+ xhr.onerror = function () {
25
+ if (typeof this.debugMode === "function" && this.debugMode())
26
+ console.error("Error occurred when loading: " + url);
27
+ if (typeof errorCallback === "function")
28
+ errorCallback();
29
+ };
30
+ xhr.onabort = function () {
31
+ if (typeof this.debugMode === "function" && this.debugMode())
32
+ console.error("Connection aborted: " + url);
33
+ if (typeof errorCallback === "function")
34
+ errorCallback();
35
+ };
36
+ xhr.ontimeout = function () {
37
+ if (typeof this.debugMode === "function" && this.debugMode())
38
+ console.error("Connection timeout: " + url);
39
+ if (typeof errorCallback === "function")
40
+ errorCallback();
41
+ };
42
+ xhr.open("GET", url, true);
43
+ xhr.send(null);
44
+ }
45
+
46
+ mt.modules = {};
47
+ mt.bindModule = function (module, dom, data, session) {
48
+ if (!module || !dom)
49
+ return;
50
+
51
+ loadFile("/modules/" + module + "/" + module + "-view.html", function (response) {
52
+ dom.innerHTML = "<link rel='stylesheet' href='/modules/" + module + "/" + module + "-style.min.css' />" + response.content;
53
+ loadFile("/modules/" + module + "/" + module + "-script.js", function (resp) {
54
+ if (!resp.content)
55
+ return;
56
+
57
+ if (!resp.cached) {
58
+ try {
59
+ eval(resp.content);
60
+ } catch (e) {
61
+ throw "Invalid module script";
62
+ }
63
+ if (!mt.modules[module])
64
+ throw "Invalid module script";
65
+ if (typeof mt.modules[module].init === "function")
66
+ mt.modules[module].init();
67
+ }
68
+
69
+ var config = mt.modules[module];
70
+
71
+ var args = { dom: dom, data: data, fnPool: config.fn, session: session };
72
+ if (typeof config.prebinding === "function") {
73
+ config.prebinding(args);
74
+ }
75
+
76
+ mt.bindDom(dom, args.data, args.fnPool, session);
77
+
78
+ if (typeof config.load === "function") {
79
+ args.dom = dom;
80
+ args.session = session;
81
+ config.load(args);
82
+ }
83
+ }, function () {
84
+ mt.bindDom(dom, data, null, session);
85
+ });
86
+
87
+
88
+ });
89
+
90
+ };
91
+
92
+ //#region mt-link
93
+ if (mt["default"] === undefined) mt["default"] = {};
94
+ if (mt["default"].mtLink === undefined) mt["default"].mtLink = {};
95
+ // cho phép mở rộng được về sau: ví dụ thay thế bằng custom dialog
96
+ mt["default"].mtLink.itemClickHandler = function (dom, message, callback) {
97
+ if (confirm(message))
98
+ callback(dom);
99
+ }
100
+
101
+ function mtLinkHandler(dom) {
102
+ mt.bindModule(dom.__mtLinkConfig.module, document.getElementById("page-wrapper"), dom.__mtLinkConfig.params);
103
+ }
104
+
105
+ function mtLinkClicked(e) {
106
+ if (this.__mtLinkConfig.confirm)
107
+ mt["default"].mtLink.itemClickHandler(this, this.__mtLinkConfig.confirm, mtLinkHandler);
108
+ else
109
+ mtLinkHandler(this);
110
+
111
+ e = e || window.event;
112
+ e.stopPropagation();
113
+ e.preventDefault();
114
+ e.cancelBubble = true;
115
+ return false;
116
+ }
117
+
118
+ mt.registerDomFeature("mtLink", function (arg) {
119
+ if (arg.dom.nodeName !== "A") {
120
+ arg.dom.dataset.mtLinkError = "mtLink feature only affects <a> tag";
121
+ return;
122
+ }
123
+
124
+ if (!arg.config.module) {
125
+ arg.dom.dataset.mtLinkError = "mtLink feature: missing module";
126
+ return;
127
+ }
128
+
129
+ arg.dom.__mtLinkConfig = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
130
+
131
+ if (!arg.dom.href)
132
+ arg.dom.href = "javascript:void(0)";
133
+
134
+ mt.fnUtils.addEventListener(arg.dom, "click", mtLinkClicked, false);
135
+
136
+ delete arg.dom.dataset.mtLink;
137
+ });
138
+ //#endregion
139
+
140
+ //#region mt-module
141
+ mt.registerDomFeature("mtModule", function (arg) {
142
+ if (!arg.config.module) {
143
+ arg.dom.dataset.mtModuleError = "mtModule feature: missing module";
144
+ return;
145
+ }
146
+
147
+ var params = mt.fnUtils.mergeData({ mask: arg.config.params, data: arg.data, session: arg.session });
148
+ mt.bindModule(arg.config.module, arg.dom, params, arg.session);
149
+ arg.mediator.skipInner = true;
150
+
151
+ delete arg.dom.dataset.mtModule;
152
+ });
153
+ //#endregion
154
+
155
+ //#region mt-inline-module
156
+ mt.inlineModuleTemplates = {};
157
+ mt.registerDomFeature("mtInlineModule", function (arg) {
158
+ var config = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
159
+
160
+ if (!config.module) {
161
+ arg.dom.dataset.mtInlineModuleError = "mtInlineModule feature: missing module";
162
+ return;
163
+ }
164
+
165
+ arg.dom.innerHTML = mt.inlineModuleTemplates[config.module] || "";
166
+
167
+ delete arg.dom.dataset.mtInlineModule;
168
+
169
+ mt.bindDom(arg.dom, config.params);
170
+
171
+ arg.mediator.skipInner = true;
172
+ });
173
+ //#endregion
174
+ })();
@@ -12,7 +12,7 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
12
12
  const roles = aliasProject.allowRoles.includes("*") ? source.roles : source.roles?.filter(r => aliasProject.allowRoles.includes(r.name));
13
13
 
14
14
  html = html.replace(/^\uFEFF/, '');
15
- html = html.replace(/<script src=(["'])\/\//g, "<script src=$1http://");
15
+ html = html.replace(/<script src="([^"]+)" data-mt-cond='\{"lazy-load": 1\}'><\/script>/g, (scriptTag, src) => `<script data-mt-cond='{"x": 1}'>${fs.readFileSync("./docs/" + src).toString()}</script>`);
16
16
  html = html.replace("</body>", `<script data-mt-cond='{"x": 1}'>
17
17
  window.data.name = ${JSON.stringify(source.name)};
18
18
  window.data.description = ${JSON.stringify(source.description)};
@@ -117,8 +117,8 @@ async function genDocs(args, projectName, project, alias, source) {
117
117
  }
118
118
  }
119
119
 
120
- console.log('Fetching https://api.siten.vn/gen/docs.html');
121
- const html = await fetch('https://api.siten.vn/gen/docs.html').then(res => res.text());
120
+ //const html = await fetch('https://api.siten.vn/gen/docs.html').then(res => res.text());
121
+ const html = fs.readFileSync("./docs/docs.html").toString();
122
122
  await processGenDocs(aliasProject, entities, source, html, args, projectName, alias);
123
123
  }
124
124
 
package/gen/gen-csharp.js CHANGED
@@ -5,7 +5,7 @@ const package = require("./../package.json");
5
5
  //#region shared function
6
6
  const newLine = `
7
7
  `;
8
- const header = `// NOTE: This file was generated by Mushroom CLI (https://www.npmjs.com/package/mushroom-cli), please do not modify
8
+ const header = `// NOTE: Please do not modify this file
9
9
  // NOTE: Version and compatibility information: please see in Info.cs file
10
10
 
11
11
  // ReSharper disable CheckNamespace
@@ -20,13 +20,7 @@ const header = `// NOTE: This file was generated by Mushroom CLI (https://www.np
20
20
  // ReSharper disable UnusedMember.Local
21
21
  // ReSharper disable UnusedParameter.Local
22
22
  // ReSharper disable UnusedTypeParameter
23
-
24
-
25
- using MongoDB.Bson;
26
- using MongoDB.Bson.Serialization.Attributes;
27
- using MongoDB.Driver;
28
- using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
29
- using NullValueHandling = Newtonsoft.Json.NullValueHandling;`;
23
+ `;
30
24
 
31
25
  function singleLine(str) {
32
26
  if (!str)
@@ -216,30 +210,30 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
216
210
  `;
217
211
 
218
212
  if (isRoot && fieldName === "id") {
219
- content += ` [BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
213
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
220
214
  }
221
- content += ` [BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
222
- [BsonIgnoreIfNull]
223
- [JsonProperty(PropertyName = "${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
215
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
216
+ [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
217
+ [Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
224
218
  `;
225
219
  if ((field.type === "AutoId" || field.type === "IdRef") && source.idType === "ObjectId") {
226
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
220
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
227
221
  }
228
222
  if (field.type === "AutoId" && source.idType === "GUID") {
229
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
223
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
230
224
  }
231
225
  if (field.type === "datetime") {
232
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
226
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
233
227
  }
234
228
  if (field.type === "array") {
235
229
  if ((field.items.type === "AutoId" || field.items.type === "IdRef") && source.idType === "ObjectId") {
236
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
230
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
237
231
  }
238
232
  if (field.items.type === "AutoId" && source.idType === "GUID") {
239
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
233
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
240
234
  }
241
235
  if (field.items.type === "datetime") {
242
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
236
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
243
237
  }
244
238
  }
245
239
 
@@ -247,7 +241,7 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
247
241
 
248
242
  strEnumClasses += generateEnumClass(source, out, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
249
243
  }
250
- content += ` [BsonExtraElements]
244
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
251
245
  public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
252
246
 
253
247
  }
@@ -289,6 +283,17 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
289
283
  let strEnumClasses = "";
290
284
  let collectionNames = "";
291
285
  let resourceNames = "";
286
+ let roleNames = "";
287
+
288
+ source.roles?.forEach(role => {
289
+ if (!role.name) return;
290
+ roleNames += `
291
+ /// <summary>
292
+ /// ${role.description ?? ""}
293
+ /// </summary>
294
+ public static string ${toCSharpName(role.name)} => "${role.name}";
295
+ `;
296
+ });
292
297
 
293
298
  const out = {};
294
299
  for (let entityName in entities) {
@@ -297,7 +302,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
297
302
 
298
303
  const className = toCSharpName(entityName);
299
304
  collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
300
- public static IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
305
+ public static MongoDB.Driver.IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
301
306
  `;
302
307
  resourceNames += ` public static string ${className} => "${entityName}";${newLine}`;
303
308
  strClasses += generateCSharpClassMongoDb(source, className, entities[entityName].fields, true, entities[entityName].description, out);
@@ -441,30 +446,26 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
441
446
  // ReSharper disable CommentTypo
442
447
  // ReSharper disable EmptyNamespace
443
448
 
444
- using MongoDB.Bson;
445
- using MongoDB.Bson.Serialization.Attributes;
446
- using MongoDB.Driver;
447
- using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
448
- using NullValueHandling = Newtonsoft.Json.NullValueHandling;
449
-
450
449
  namespace ${namespace}
451
450
  {
451
+ using MongoDB.Driver;
452
+
452
453
  public static class DbConnector
453
454
  {
454
455
  ${collectionNames}
455
456
  public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
456
457
 
457
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
458
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
458
459
  {
459
460
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
460
461
  }
461
462
 
462
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, FindOptions<T> findOptions) where T : Mushroom.Models.IResource<TId>
463
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id, FindOptions<T> findOptions) where T : Mushroom.Models.IResource<TId>
463
464
  {
464
465
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
465
466
  }
466
467
 
467
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, ProjectionDefinition<T> projection) where T : Mushroom.Models.IResource<TId>
468
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id, ProjectionDefinition<T> projection) where T : Mushroom.Models.IResource<TId>
468
469
  {
469
470
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
470
471
  }
@@ -474,6 +475,10 @@ ${collectionNames}
474
475
  {
475
476
  ${resourceNames}
476
477
  }
478
+
479
+ public static class RoleNames {
480
+ ${roleNames}
481
+ }
477
482
  }
478
483
 
479
484
  namespace ${namespace}.Resources
@@ -575,30 +580,30 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
575
580
  `;
576
581
 
577
582
  if (isRoot && fieldName === "id") {
578
- content += ` [BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
583
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
579
584
  }
580
- content += ` [BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
581
- [BsonIgnoreIfNull]
582
- [JsonProperty(PropertyName = "${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
585
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
586
+ [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
587
+ [Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
583
588
  `;
584
589
  if ((field.type === "AutoId" || field.type === "IdRef") && source.idType === "ObjectId") {
585
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
590
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
586
591
  }
587
592
  if (field.type === "AutoId" && source.idType === "GUID") {
588
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
593
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
589
594
  }
590
595
  if (field.type === "datetime") {
591
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
596
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
592
597
  }
593
598
  if (field.type === "array") {
594
599
  if ((field.items.type === "AutoId" || field.items.type === "IdRef") && source.idType === "ObjectId") {
595
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
600
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
596
601
  }
597
602
  if (field.items.type === "AutoId" && source.idType === "GUID") {
598
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
603
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
599
604
  }
600
605
  if (field.items.type === "datetime") {
601
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
606
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
602
607
  }
603
608
  }
604
609
 
@@ -622,7 +627,8 @@ ${strEnumClasses}
622
627
  fs.writeFileSync(aliasProject.output + "/Enums/" + match[1] + ".cs", strEnumClasses);
623
628
  }
624
629
 
625
- content += ` [BsonExtraElements]
630
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
631
+ [Newtonsoft.Json.JsonIgnore]
626
632
  public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
627
633
 
628
634
  }
@@ -649,7 +655,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
649
655
  fs.unlinkSync(aliasProject.output); // xóa file nếu có
650
656
  } catch(e) {}
651
657
  try {
652
- fs.rmdirSync(aliasProject.output); // xóa thư mục nếu có
658
+ fs.rmdirSync(aliasProject.output, { recursive: true, force: true }); // xóa thư mục nếu có
653
659
  } catch(e) {}
654
660
  }
655
661
  fs.mkdirSync(aliasProject.output, { recursive: true, mode: 0755 });
@@ -660,6 +666,17 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
660
666
 
661
667
  let collectionNames = "";
662
668
  let resourceNames = "";
669
+ let roleNames = "";
670
+
671
+ source.roles?.forEach(role => {
672
+ if (!role.name) return;
673
+ roleNames += `
674
+ /// <summary>
675
+ /// ${role.description ?? ""}
676
+ /// </summary>
677
+ public static string ${toCSharpName(role.name)} => "${role.name}";
678
+ `;
679
+ });
663
680
 
664
681
  const out = {};
665
682
  for (let entityName in entities) {
@@ -668,7 +685,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
668
685
 
669
686
  const className = toCSharpName(entityName);
670
687
  collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
671
- public static IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
688
+ public static MongoDB.Driver.IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
672
689
  `;
673
690
  resourceNames += ` public static string ${className} => "${entityName}";
674
691
  `;
@@ -799,6 +816,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
799
816
  : "";
800
817
 
801
818
  const dbConnectorFileContent = `${header}
819
+ using MongoDB.Driver;
802
820
 
803
821
  namespace ${namespace}
804
822
  {
@@ -807,17 +825,17 @@ namespace ${namespace}
807
825
  ${collectionNames}
808
826
  public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
809
827
 
810
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
828
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
811
829
  {
812
830
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
813
831
  }
814
832
 
815
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, FindOptions<T> findOptions) where T : Mushroom.Models.IResource<TId>
833
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id, FindOptions<T> findOptions) where T : Mushroom.Models.IResource<TId>
816
834
  {
817
835
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
818
836
  }
819
837
 
820
- public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, ProjectionDefinition<T> projection) where T : Mushroom.Models.IResource<TId>
838
+ public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this MongoDB.Driver.IMongoCollection<T> collection, TId id, ProjectionDefinition<T> projection) where T : Mushroom.Models.IResource<TId>
821
839
  {
822
840
  return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
823
841
  }
@@ -835,6 +853,18 @@ ${resourceNames}
835
853
  }
836
854
  }
837
855
  `;
856
+
857
+ const roleNamesFileContent = `${header}
858
+
859
+ namespace ${namespace}
860
+ {
861
+ public static class RoleNames
862
+ {
863
+ ${roleNames}
864
+ }
865
+ }
866
+ `;
867
+
838
868
 
839
869
  const refactorHelperFileContent = `${header}
840
870
 
@@ -867,6 +897,7 @@ ${strJobReferences}
867
897
 
868
898
  fs.writeFileSync(aliasProject.output + "/DbConnector.cs", dbConnectorFileContent);
869
899
  fs.writeFileSync(aliasProject.output + "/ResourceNames.cs", resourceNamesFileContent);
900
+ fs.writeFileSync(aliasProject.output + "/RoleNames.cs", roleNamesFileContent);
870
901
  fs.writeFileSync(aliasProject.output + "/RefactorHelper.cs", refactorHelperFileContent);
871
902
  fs.writeFileSync(aliasProject.output + "/Info.cs", infoFileContent);
872
903
 
@@ -915,7 +946,7 @@ function generateCSharpClassDriver(source, className, fields, description, out)
915
946
  ` /// <summary>
916
947
  /// ${singleLine(field.description)}
917
948
  /// </summary>
918
- [JsonProperty(PropertyName ="${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
949
+ [Newtonsoft.Json.JsonProperty(PropertyName ="${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
919
950
  public ${type} ${propertyName} { get; set; }
920
951
 
921
952
  `;
@@ -1181,7 +1212,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1181
1212
  var type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
1182
1213
  if (p.isArray)
1183
1214
  type = `System.Collections.Generic.List<${type}>`;
1184
- viewExtraClass += ` [JsonProperty(PropertyName = "${p.field}")]
1215
+ viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}")]
1185
1216
  public ${type} ${toCSharpName(p.field)} { get; set; }
1186
1217
 
1187
1218
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.1.0-alpha.13",
3
+ "version": "1.1.0-alpha.16",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "author": "suco2007",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "jsdom": "^19.0.0",
20
+ "jsdom": "^20.0.0",
21
21
  "json5": "^2.2.1",
22
22
  "node-fetch": "^2.6.7",
23
23
  "open": "^8.4.0",