@wzyjs/next 0.3.0 → 0.3.2

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.
@@ -27,7 +27,10 @@ interface Option<TList extends FindManyArgs = FindManyArgs, TInfo extends FindUn
27
27
  query: SelectSubset<TInfo, FindUniqueArgs>
28
28
  option?: UseOptions<GetPayload<TInfo> | null>
29
29
  }
30
- allTags?: true
30
+ tags?: true | {
31
+ query?: Parameters<typeof api.habitGroup.getAllTags.useQuery>[0]
32
+ option?: UseOptions<string[]>
33
+ }
31
34
  create?: Parameters<typeof api.habitGroup.create.useMutation>[0]
32
35
  update?: Parameters<typeof api.habitGroup.update.useMutation>[0]
33
36
  remove?: Parameters<typeof api.habitGroup.update.useMutation>[0]
@@ -47,7 +50,7 @@ const r = (q: any) => {
47
50
  }
48
51
 
49
52
  export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs>(option: Option<TList, TInfo> = {}) => {
50
- const { list, info, create, update, remove, allTags = false, delete: deleteOption, showTip = true } = option
53
+ const { list, info, create, update, remove, tags = false, delete: deleteOption, showTip = true } = option
51
54
 
52
55
  const apiUtils = api.useUtils()
53
56
 
@@ -66,8 +69,15 @@ export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TIn
66
69
  ...(info ? info.option : undefined),
67
70
  })
68
71
 
69
- const allTagsState = api.habitGroup.getAllTags.useQuery(undefined, {
70
- enabled: allTags,
72
+ const tagsConfig: Option['tags'] | false = tags
73
+ const tagsEnabled: boolean = Boolean(tagsConfig)
74
+ const tagsQuery: Parameters<typeof api.habitGroup.getAllTags.useQuery>[0] = (
75
+ tagsConfig && typeof tagsConfig === 'object' ? tagsConfig.query : undefined
76
+ ) as Parameters<typeof api.habitGroup.getAllTags.useQuery>[0]
77
+
78
+ const tagsState = api.habitGroup.getAllTags.useQuery(tagsQuery, {
79
+ enabled: tagsEnabled,
80
+ ...(tagsConfig && typeof tagsConfig === 'object' ? tagsConfig.option : undefined),
71
81
  })
72
82
 
73
83
  const onSuccess = (tip: string) => {
@@ -183,7 +193,7 @@ export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TIn
183
193
 
184
194
  infoState,
185
195
 
186
- allTagsState,
196
+ tagsState,
187
197
 
188
198
  createState,
189
199
  updateState,
@@ -40,7 +40,7 @@ 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 dataModels, modelsWithTags, _i, modelsWithTags_1, dataModel, modelName, routerFilePath, fileContent, getAllTagsInterface, lastCommaIndex, closingBraceIndex, beforeInsertion, afterInsertion, newContent;
43
+ var dataModels, modelsWithTags, _i, modelsWithTags_1, dataModel, modelName, routerFilePath, fileContent, zImport, procedureImportToken, delegateName, getAllTagsInterface, existingMatch, newContent, lastCommaIndex, closingBraceIndex, beforeInsertion, afterInsertion;
44
44
  return __generator(this, function (_a) {
45
45
  dataModels = model.declarations.filter(function (item) { return item.$type === 'DataModel'; });
46
46
  modelsWithTags = dataModels;
@@ -60,11 +60,21 @@ var generateTags = function (model, outputPath) { return __awaiter(void 0, void
60
60
  continue;
61
61
  }
62
62
  fileContent = fs.readFileSync(routerFilePath, 'utf-8');
63
- // 检查是否已经添加了 getAllTags 接口
64
- if (fileContent.includes('getAllTags:')) {
63
+ zImport = 'import { z } from "@/api/utils";';
64
+ if (!fileContent.includes(zImport)) {
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');
65
76
  continue;
66
77
  }
67
- getAllTagsInterface = "\n getAllTags: procedure.query(async ({ ctx }) => {\n const records = await checkRead(db(ctx).".concat(modelName.charAt(0).toLowerCase() + modelName.slice(1), ".findMany({\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 }),");
68
78
  lastCommaIndex = fileContent.lastIndexOf(',');
69
79
  closingBraceIndex = fileContent.indexOf('\n }\n );', lastCommaIndex);
70
80
  if (closingBraceIndex === -1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/next",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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": "61bf121b8d0b34cc7e4a8875c17e409f32dd4d74",
20
+ "gitHead": "22c3d24e9f596ff0171bf93c85d17c9615690981",
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  }