@wzyjs/next 0.3.2 → 0.3.4
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/dist/Base.zmodel +25 -21
- package/dist/index.js +4 -6
- package/dist/plugin/tags/index.js +6 -16
- package/package.json +2 -2
package/dist/Base.zmodel
CHANGED
|
@@ -12,45 +12,49 @@ datasource db {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
plugin prisma {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
provider = '@core/prisma'
|
|
16
|
+
output = './schema.prisma'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
plugin enhancer {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
provider = '@core/enhancer'
|
|
21
|
+
output = '../src/api/generated/enhancer'
|
|
22
|
+
preserveTsFiles = true
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
plugin zod {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
provider = '@core/zod'
|
|
27
|
+
output = '../src/api/generated/zod'
|
|
28
|
+
compile = false
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
plugin trpc {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
provider = '@zenstackhq/trpc'
|
|
33
|
+
output = '../src/api/generated/trpc'
|
|
34
|
+
version = 'v11'
|
|
35
|
+
generateClientHelpers = 'next'
|
|
36
|
+
importCreateRouter = "@/api/trpc/trpc"
|
|
37
|
+
importProcedure = "@/api/trpc/procedures"
|
|
38
|
+
zodSchemasImport = '@/api/generated/zod'
|
|
39
|
+
generateModelActions = 'findMany, findUnique, create, update, updateMany, delete, deleteMany, count'
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
plugin crud_tags {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
provider = '@wzyjs/next'
|
|
44
|
+
title = 'Generate Some Api'
|
|
45
|
+
output = 'src/api/generated'
|
|
46
|
+
generateActions = 'crud, tags'
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
abstract model Base {
|
|
50
50
|
id String @id @default(cuid())
|
|
51
|
+
|
|
51
52
|
createdAt DateTime @default(now())
|
|
52
53
|
updatedAt DateTime? @updatedAt
|
|
53
|
-
|
|
54
|
+
|
|
55
|
+
sort Int?
|
|
56
|
+
enabled Boolean @default(true)
|
|
57
|
+
isDeleted Boolean @default(false) @omit
|
|
54
58
|
|
|
55
59
|
@@allow('all', !isDeleted)
|
|
56
60
|
}
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ var tags_1 = require("./plugin/tags");
|
|
|
43
43
|
exports.name = 'Generate CRUD and Tags';
|
|
44
44
|
function run(model, options) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var outputPath, generateActions
|
|
46
|
+
var outputPath, generateActions;
|
|
47
47
|
return __generator(this, function (_a) {
|
|
48
48
|
switch (_a.label) {
|
|
49
49
|
case 0:
|
|
@@ -52,16 +52,14 @@ function run(model, options) {
|
|
|
52
52
|
throw new Error('output is required');
|
|
53
53
|
}
|
|
54
54
|
outputPath = String(options.output);
|
|
55
|
-
generateActions = String(options.generateActions || 'crud,tags');
|
|
56
|
-
|
|
57
|
-
console.log();
|
|
58
|
-
if (!actions.includes('crud')) return [3 /*break*/, 2];
|
|
55
|
+
generateActions = String(options.generateActions || 'crud, tags').replace(/\s/g, '').toLowerCase().split(',');
|
|
56
|
+
if (!generateActions.includes('crud')) return [3 /*break*/, 2];
|
|
59
57
|
return [4 /*yield*/, (0, crud_1.generateCRUD)(model, outputPath)];
|
|
60
58
|
case 1:
|
|
61
59
|
_a.sent();
|
|
62
60
|
_a.label = 2;
|
|
63
61
|
case 2:
|
|
64
|
-
if (!
|
|
62
|
+
if (!generateActions.includes('tags')) return [3 /*break*/, 4];
|
|
65
63
|
return [4 /*yield*/, (0, tags_1.generateTags)(model, outputPath)];
|
|
66
64
|
case 3:
|
|
67
65
|
_a.sent();
|
|
@@ -40,10 +40,9 @@ exports.generateTags = void 0;
|
|
|
40
40
|
var fs = require("node:fs");
|
|
41
41
|
var path = require("node:path");
|
|
42
42
|
var generateTags = function (model, outputPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var
|
|
43
|
+
var modelsWithTags, _i, modelsWithTags_1, dataModel, modelName, routerFilePath, fileContent, delegateName, getAllTagsInterface, lastCommaIndex, closingBraceIndex, beforeInsertion, afterInsertion, newContent;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
|
-
|
|
46
|
-
modelsWithTags = dataModels;
|
|
45
|
+
modelsWithTags = model.declarations.filter(function (item) { return item.$type === 'DataModel'; });
|
|
47
46
|
// .filter(dataModel => {
|
|
48
47
|
// return dataModel.fields.some(field => field.name === 'tags')
|
|
49
48
|
// })
|
|
@@ -60,21 +59,12 @@ var generateTags = function (model, outputPath) { return __awaiter(void 0, void
|
|
|
60
59
|
continue;
|
|
61
60
|
}
|
|
62
61
|
fileContent = fs.readFileSync(routerFilePath, 'utf-8');
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
procedureImportToken = 'import { procedure } from "@/api/trpc/procedures";';
|
|
66
|
-
if (fileContent.includes(procedureImportToken)) {
|
|
67
|
-
fileContent = fileContent.replace(procedureImportToken, "".concat(procedureImportToken, "\n").concat(zImport));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
delegateName = modelName.charAt(0).toLowerCase() + modelName.slice(1);
|
|
71
|
-
getAllTagsInterface = "\n getAllTags: procedure\n .input(z.object({ where: z.any().optional() }).optional())\n .query(async ({ ctx, input }) => {\n const records = await checkRead(db(ctx).".concat(delegateName, ".findMany({\n ...(input?.where ? { where: input.where } : {}),\n select: { tags: true },\n }))\n\n const uniqueTags = Array.from(new Set(records.flatMap(record => record.tags || [])))\n\n return uniqueTags\n }),");
|
|
72
|
-
existingMatch = fileContent.match(/\n\s*getAllTags:\s*procedure[\s\S]*?\n\s*\}\),/m);
|
|
73
|
-
if (existingMatch === null || existingMatch === void 0 ? void 0 : existingMatch[0]) {
|
|
74
|
-
newContent = fileContent.replace(existingMatch[0], "\n".concat(getAllTagsInterface));
|
|
75
|
-
fs.writeFileSync(routerFilePath, newContent, 'utf-8');
|
|
62
|
+
// 检查是否已经添加了 getAllTags 接口
|
|
63
|
+
if (fileContent.includes('getAllTags:')) {
|
|
76
64
|
continue;
|
|
77
65
|
}
|
|
66
|
+
delegateName = modelName.charAt(0).toLowerCase() + modelName.slice(1);
|
|
67
|
+
getAllTagsInterface = "\n getAllTags: procedure\n .query(async ({ ctx, input }) => {\n const records = await checkRead(db(ctx).".concat(delegateName, ".findMany({\n ...(input?.where ? { where: input.where } : {}),\n select: { tags: true },\n }))\n\n // \u6241\u5E73\u5316 + \u53BB\u91CD\n const uniqueTags = Array.from(new Set(records.flatMap(record => record.tags || [])))\n\n return uniqueTags\n }),");
|
|
78
68
|
lastCommaIndex = fileContent.lastIndexOf(',');
|
|
79
69
|
closingBraceIndex = fileContent.indexOf('\n }\n );', lastCommaIndex);
|
|
80
70
|
if (closingBraceIndex === -1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/next",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@zenstackhq/sdk": "^2.12.3"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "759abaadc6f778c5a1b4ddb5b16f7753d45f37f9",
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
}
|