mushroom-cli 1.2.0-alpha.5 → 1.2.0-alpha.6
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/README.md +11 -0
- package/docs/docs.html +3 -3
- package/gen/gen-csharp.js +3 -18
- package/gen/gen-ts-driver.js +15 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,17 @@ Disable checking for update:
|
|
|
88
88
|
|
|
89
89
|
## Version
|
|
90
90
|
|
|
91
|
+
### 1.2.0-alpha.6
|
|
92
|
+
|
|
93
|
+
New features:
|
|
94
|
+
|
|
95
|
+
* gen-ts-driver: Support offline mode
|
|
96
|
+
|
|
97
|
+
Changes:
|
|
98
|
+
|
|
99
|
+
* gen-api-docs: Improve generating api-docs
|
|
100
|
+
* gen-csharp: Generate resource classes with `partial`
|
|
101
|
+
|
|
91
102
|
### 1.2.0-alpha.5
|
|
92
103
|
|
|
93
104
|
New features:
|
package/docs/docs.html
CHANGED
|
@@ -2614,7 +2614,7 @@ Token: your token</span>
|
|
|
2614
2614
|
|
|
2615
2615
|
<span class="place-holder">BODY DATA</span></pre>
|
|
2616
2616
|
Nếu webserver chỉ hỗ trợ các http method thông dụng, không hỗ trợ http method <span data-mt-attr='{"text": {"fn": "getHttpMethod", "data": "$actionName"}}'></span> thì sử dụng Header theo cách sau:
|
|
2617
|
-
<pre data-language="http">TRƯỜNG HỢP CÓ BODY DATA
|
|
2617
|
+
<pre data-language="http"><span data-mt-cond='{"action.codeHint.delegator.requestBody": {"$exists": false}}'>TRƯỜNG HỢP CÓ BODY DATA</span>
|
|
2618
2618
|
POST <span data-mt-attr='{"text": {"fn": "getApiPath"}}'></span><span data-mt-attr='{"text": "$entityName"}'></span>s/<span data-mt-attr='{"text": {"fn": "getHttpMethod", "data": "$actionName"}}'></span><span class="place-holder">?param1=value1&param2=value2</span> HTTP/1.1
|
|
2619
2619
|
Host: <span data-mt-attr='{"text": {"fn": "getApiDomain"}}'></span>
|
|
2620
2620
|
Content-Type: application/json
|
|
@@ -2622,13 +2622,13 @@ X-HTTP-Method-Override: <span data-mt-attr='{"text": {"fn": "getHttpMethod", "da
|
|
|
2622
2622
|
Token: your token</span>
|
|
2623
2623
|
|
|
2624
2624
|
<span class="place-holder">BODY DATA</span>
|
|
2625
|
-
|
|
2625
|
+
<span data-mt-cond='{"action.codeHint.delegator.requestBody": {"$exists": false}}'>
|
|
2626
2626
|
TRƯỜNG HỢP KHÔNG CÓ BODY DATA
|
|
2627
2627
|
GET <span data-mt-attr='{"text": {"fn": "getApiPath"}}'></span><span data-mt-attr='{"text": "$entityName"}'></span>s/<span data-mt-attr='{"text": {"fn": "getHttpMethod", "data": "$actionName"}}'></span><span class="place-holder">?param1=value1&param2=value2</span> HTTP/1.1
|
|
2628
2628
|
Host: <span data-mt-attr='{"text": {"fn": "getApiDomain"}}'></span>
|
|
2629
2629
|
Content-Type: application/json
|
|
2630
2630
|
X-HTTP-Method-Override: <span data-mt-attr='{"text": {"fn": "getHttpMethod", "data": "$actionName"}}'></span><span data-mt-cond='{"action.grant": {"$ne": "*"}}'>
|
|
2631
|
-
Token: your token</span>
|
|
2631
|
+
Token: your token</span></span>
|
|
2632
2632
|
</pre>
|
|
2633
2633
|
</div>
|
|
2634
2634
|
</div>
|
package/gen/gen-csharp.js
CHANGED
|
@@ -134,7 +134,7 @@ function generateEnumClass(source, out, field, defaultClassName) {
|
|
|
134
134
|
strEnumClasses += ` /// <summary>
|
|
135
135
|
/// ${singleLine(validation.codeHint.validValues.description || field.description)}
|
|
136
136
|
/// </summary>
|
|
137
|
-
public class ${enumClassName}
|
|
137
|
+
public partial class ${enumClassName}
|
|
138
138
|
{
|
|
139
139
|
private ${enumClassName}() { }
|
|
140
140
|
|
|
@@ -179,7 +179,7 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
|
|
|
179
179
|
|
|
180
180
|
supperClass = " : Mushroom.Models.IResource<" + getCSharpTypeFromMushroomType(source, fields.id.type, true) + ">";
|
|
181
181
|
}
|
|
182
|
-
content += ` public class ${className}${supperClass}
|
|
182
|
+
content += ` public partial class ${className}${supperClass}
|
|
183
183
|
{
|
|
184
184
|
`;
|
|
185
185
|
for (var fieldName in fields) {
|
|
@@ -488,21 +488,6 @@ namespace ${namespace}
|
|
|
488
488
|
{
|
|
489
489
|
${collectionNames}
|
|
490
490
|
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
491
|
-
|
|
492
|
-
public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
|
|
493
|
-
{
|
|
494
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
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>
|
|
498
|
-
{
|
|
499
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
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>
|
|
503
|
-
{
|
|
504
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
|
|
505
|
-
}
|
|
506
491
|
}
|
|
507
492
|
|
|
508
493
|
public class ResourceNames
|
|
@@ -587,7 +572,7 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
|
|
|
587
572
|
|
|
588
573
|
supperClass = " : Mushroom.Models.IResource<" + getCSharpTypeFromMushroomType(source, fields.id.type, true) + ">";
|
|
589
574
|
}
|
|
590
|
-
content += ` public class ${className}${supperClass}
|
|
575
|
+
content += ` public partial class ${className}${supperClass}
|
|
591
576
|
{
|
|
592
577
|
`;
|
|
593
578
|
for (var fieldName in fields) {
|
package/gen/gen-ts-driver.js
CHANGED
|
@@ -125,7 +125,7 @@ function genTypescriptDriverString(aliasProject, source) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
128
|
+
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResponseDataType, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError, IMushroomOfflineResponse, MushroomOfflineResponse, MushroomOfflineResponseState } from "mushroomjs";
|
|
129
129
|
${extensionsImportLines.join("\n")}
|
|
130
130
|
export * from "mushroomjs";
|
|
131
131
|
export const extensions = {
|
|
@@ -156,7 +156,12 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
156
156
|
|
|
157
157
|
actions[actionName] = {
|
|
158
158
|
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined,
|
|
159
|
-
includeTotal: actionName === "findMany" && entity.actions[actionName].some(a => a.includeTotal) ? true: undefined
|
|
159
|
+
includeTotal: actionName === "findMany" && entity.actions[actionName].some(a => a.includeTotal) ? true: undefined,
|
|
160
|
+
offlineMode: entity.actions[actionName].some(a => a.offlineMode === "disallow")
|
|
161
|
+
? "disallow"
|
|
162
|
+
: !entity.actions[actionName].length || entity.actions[actionName].some(a => a.offlineMode === "allow")
|
|
163
|
+
? "allow"
|
|
164
|
+
: undefined
|
|
160
165
|
};
|
|
161
166
|
|
|
162
167
|
switch (actionName) {
|
|
@@ -299,7 +304,7 @@ function genDtsString(aliasProject, source) {
|
|
|
299
304
|
}
|
|
300
305
|
}
|
|
301
306
|
|
|
302
|
-
let code = `import { IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
307
|
+
let code = `import { IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResponseDataType, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError, IMushroomOfflineResponse, MushroomOfflineResponse, MushroomOfflineResponseState } from "mushroomjs";
|
|
303
308
|
${extensionsImportLines.join("\n")}
|
|
304
309
|
export * from "mushroomjs";
|
|
305
310
|
export declare const extensions = {
|
|
@@ -329,7 +334,13 @@ export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType =
|
|
|
329
334
|
continue;
|
|
330
335
|
|
|
331
336
|
actions[actionName] = {
|
|
332
|
-
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
|
|
337
|
+
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined,
|
|
338
|
+
includeTotal: actionName === "findMany" && entity.actions[actionName].some(a => a.includeTotal) ? true: undefined,
|
|
339
|
+
offlineMode: entity.actions[actionName].some(a => a.offlineMode === "disallow")
|
|
340
|
+
? "disallow"
|
|
341
|
+
: !entity.actions[actionName].length || entity.actions[actionName].some(a => a.offlineMode === "allow")
|
|
342
|
+
? "allow"
|
|
343
|
+
: undefined
|
|
333
344
|
};
|
|
334
345
|
|
|
335
346
|
switch (actionName) {
|