mushroom-cli 1.1.0-alpha.15 → 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.
- package/gen/gen-csharp.js +37 -46
- package/package.json +1 -1
package/gen/gen-csharp.js
CHANGED
|
@@ -20,13 +20,7 @@ const header = `// NOTE: Please do not modify this file
|
|
|
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
|
}
|
|
@@ -308,7 +302,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
|
|
|
308
302
|
|
|
309
303
|
const className = toCSharpName(entityName);
|
|
310
304
|
collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
|
|
311
|
-
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);
|
|
312
306
|
`;
|
|
313
307
|
resourceNames += ` public static string ${className} => "${entityName}";${newLine}`;
|
|
314
308
|
strClasses += generateCSharpClassMongoDb(source, className, entities[entityName].fields, true, entities[entityName].description, out);
|
|
@@ -452,30 +446,26 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
|
|
|
452
446
|
// ReSharper disable CommentTypo
|
|
453
447
|
// ReSharper disable EmptyNamespace
|
|
454
448
|
|
|
455
|
-
using MongoDB.Bson;
|
|
456
|
-
using MongoDB.Bson.Serialization.Attributes;
|
|
457
|
-
using MongoDB.Driver;
|
|
458
|
-
using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
|
|
459
|
-
using NullValueHandling = Newtonsoft.Json.NullValueHandling;
|
|
460
|
-
|
|
461
449
|
namespace ${namespace}
|
|
462
450
|
{
|
|
451
|
+
using MongoDB.Driver;
|
|
452
|
+
|
|
463
453
|
public static class DbConnector
|
|
464
454
|
{
|
|
465
455
|
${collectionNames}
|
|
466
456
|
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
467
457
|
|
|
468
|
-
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>
|
|
469
459
|
{
|
|
470
460
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
|
|
471
461
|
}
|
|
472
462
|
|
|
473
|
-
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>
|
|
474
464
|
{
|
|
475
465
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
|
|
476
466
|
}
|
|
477
467
|
|
|
478
|
-
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>
|
|
479
469
|
{
|
|
480
470
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
|
|
481
471
|
}
|
|
@@ -590,30 +580,30 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
|
|
|
590
580
|
`;
|
|
591
581
|
|
|
592
582
|
if (isRoot && fieldName === "id") {
|
|
593
|
-
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}`;
|
|
594
584
|
}
|
|
595
|
-
content += ` [BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
|
|
596
|
-
[BsonIgnoreIfNull]
|
|
597
|
-
[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)]
|
|
598
588
|
`;
|
|
599
589
|
if ((field.type === "AutoId" || field.type === "IdRef") && source.idType === "ObjectId") {
|
|
600
|
-
content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
|
|
590
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
|
|
601
591
|
}
|
|
602
592
|
if (field.type === "AutoId" && source.idType === "GUID") {
|
|
603
|
-
content += " [BsonRepresentation(BsonType.String)]" + newLine;
|
|
593
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
|
|
604
594
|
}
|
|
605
595
|
if (field.type === "datetime") {
|
|
606
|
-
content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
|
|
596
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
|
|
607
597
|
}
|
|
608
598
|
if (field.type === "array") {
|
|
609
599
|
if ((field.items.type === "AutoId" || field.items.type === "IdRef") && source.idType === "ObjectId") {
|
|
610
|
-
content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
|
|
600
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
|
|
611
601
|
}
|
|
612
602
|
if (field.items.type === "AutoId" && source.idType === "GUID") {
|
|
613
|
-
content += " [BsonRepresentation(BsonType.String)]" + newLine;
|
|
603
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
|
|
614
604
|
}
|
|
615
605
|
if (field.items.type === "datetime") {
|
|
616
|
-
content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
|
|
606
|
+
content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
|
|
617
607
|
}
|
|
618
608
|
}
|
|
619
609
|
|
|
@@ -637,8 +627,8 @@ ${strEnumClasses}
|
|
|
637
627
|
fs.writeFileSync(aliasProject.output + "/Enums/" + match[1] + ".cs", strEnumClasses);
|
|
638
628
|
}
|
|
639
629
|
|
|
640
|
-
content += ` [BsonExtraElements]
|
|
641
|
-
[JsonIgnore]
|
|
630
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
|
|
631
|
+
[Newtonsoft.Json.JsonIgnore]
|
|
642
632
|
public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
|
|
643
633
|
|
|
644
634
|
}
|
|
@@ -695,7 +685,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
|
|
|
695
685
|
|
|
696
686
|
const className = toCSharpName(entityName);
|
|
697
687
|
collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
|
|
698
|
-
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);
|
|
699
689
|
`;
|
|
700
690
|
resourceNames += ` public static string ${className} => "${entityName}";
|
|
701
691
|
`;
|
|
@@ -826,6 +816,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
|
|
|
826
816
|
: "";
|
|
827
817
|
|
|
828
818
|
const dbConnectorFileContent = `${header}
|
|
819
|
+
using MongoDB.Driver;
|
|
829
820
|
|
|
830
821
|
namespace ${namespace}
|
|
831
822
|
{
|
|
@@ -834,17 +825,17 @@ namespace ${namespace}
|
|
|
834
825
|
${collectionNames}
|
|
835
826
|
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
836
827
|
|
|
837
|
-
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>
|
|
838
829
|
{
|
|
839
830
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
|
|
840
831
|
}
|
|
841
832
|
|
|
842
|
-
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>
|
|
843
834
|
{
|
|
844
835
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
|
|
845
836
|
}
|
|
846
837
|
|
|
847
|
-
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>
|
|
848
839
|
{
|
|
849
840
|
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
|
|
850
841
|
}
|
|
@@ -955,7 +946,7 @@ function generateCSharpClassDriver(source, className, fields, description, out)
|
|
|
955
946
|
` /// <summary>
|
|
956
947
|
/// ${singleLine(field.description)}
|
|
957
948
|
/// </summary>
|
|
958
|
-
[JsonProperty(PropertyName ="${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
|
|
949
|
+
[Newtonsoft.Json.JsonProperty(PropertyName ="${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
|
959
950
|
public ${type} ${propertyName} { get; set; }
|
|
960
951
|
|
|
961
952
|
`;
|
|
@@ -1221,7 +1212,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
|
|
|
1221
1212
|
var type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
|
|
1222
1213
|
if (p.isArray)
|
|
1223
1214
|
type = `System.Collections.Generic.List<${type}>`;
|
|
1224
|
-
viewExtraClass += ` [JsonProperty(PropertyName = "${p.field}")]
|
|
1215
|
+
viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}")]
|
|
1225
1216
|
public ${type} ${toCSharpName(p.field)} { get; set; }
|
|
1226
1217
|
|
|
1227
1218
|
`;
|