@wzyjs/next 0.3.23 → 0.3.24

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.
@@ -1,5 +1,5 @@
1
1
  // @ts-ignore
2
- import { message } from '@/components'
2
+ import { App } from '@/components'
3
3
 
4
4
  // @ts-ignore
5
5
  import { trpc as api } from '@/api/react'
@@ -55,22 +55,24 @@ const r = (q: any) => {
55
55
  export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TInfo extends FindUniqueArgs = FindUniqueArgs>(option: Option<TList, TInfo> = {}) => {
56
56
  const { list, info, create, update, remove, tags = false, delete: deleteOption, showTip = true } = option
57
57
 
58
+ const { message } = App.useApp()
59
+
58
60
  const apiUtils = api.useUtils()
59
61
 
60
62
  const listState = api.habitGroup.findMany.useQuery(list === false ? undefined : list?.query, {
61
63
  enabled: list !== false,
62
64
  ...(list ? list.option : undefined),
63
- } as any)
65
+ })
64
66
 
65
67
  const countState = api.habitGroup.count.useQuery(list === false ? {} as any : r(list?.query), {
66
68
  enabled: list !== false,
67
69
  ...(list ? list.option : undefined),
68
- } as any)
70
+ })
69
71
 
70
72
  const infoState = api.habitGroup.findUnique.useQuery(info?.query || {} as any, {
71
73
  enabled: !!info,
72
74
  ...(info ? info.option : undefined),
73
- } as any)
75
+ })
74
76
 
75
77
  const tagsConfig: Option['tags'] | false = tags
76
78
  const tagsEnabled: boolean = Boolean(tagsConfig)
@@ -81,7 +83,7 @@ export const useHabitGroupCRUD = <TList extends FindManyArgs = FindManyArgs, TIn
81
83
  const tagsState = api.habitGroup.getAllTags.useQuery(tagsQuery as any, {
82
84
  enabled: tagsEnabled,
83
85
  ...(tagsConfig && typeof tagsConfig === 'object' ? tagsConfig.option : undefined),
84
- } as any)
86
+ })
85
87
 
86
88
  const onSuccess = (tip: string) => {
87
89
  message.destroy()
@@ -42,26 +42,29 @@ var path = require("node:path");
42
42
  var generateTags = function (model, outputPath) { return __awaiter(void 0, void 0, void 0, function () {
43
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
- modelsWithTags = model.declarations.filter(function (item) {
46
- if (item.$type !== 'DataModel') return false;
47
- return item.fields.some(function (field) { return field.name === 'tags'; });
48
- });
45
+ modelsWithTags = model.declarations.filter(function (item) { return item.$type === 'DataModel'; });
46
+ // .filter(dataModel => {
47
+ // return dataModel.fields.some(field => field.name === 'tags')
48
+ // })
49
49
  if (modelsWithTags.length === 0) {
50
50
  return [2 /*return*/];
51
51
  }
52
+ // 为每个有 tags 字段的模型添加 getAllTags 接口
52
53
  for (_i = 0, modelsWithTags_1 = modelsWithTags; _i < modelsWithTags_1.length; _i++) {
53
54
  dataModel = modelsWithTags_1[_i];
54
55
  modelName = String(dataModel.name);
55
56
  routerFilePath = path.join(outputPath, 'trpc', 'routers', "".concat(modelName, ".router.ts"));
57
+ // 检查文件是否存在
56
58
  if (!fs.existsSync(routerFilePath)) {
57
59
  continue;
58
60
  }
59
61
  fileContent = fs.readFileSync(routerFilePath, 'utf-8');
62
+ // 检查是否已经添加了 getAllTags 接口
60
63
  if (fileContent.includes('getAllTags:')) {
61
64
  continue;
62
65
  }
63
66
  delegateName = modelName.charAt(0).toLowerCase() + modelName.slice(1);
64
- getAllTagsInterface = "\n getAllTags: procedure\n .query(async ({ ctx, input }) => {\n const records = await checkRead(db(ctx)." + 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 }),";
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 }),");
65
68
  lastCommaIndex = fileContent.lastIndexOf(',');
66
69
  closingBraceIndex = fileContent.indexOf('\n }\n );', lastCommaIndex);
67
70
  if (closingBraceIndex === -1) {
@@ -71,10 +74,11 @@ var generateTags = function (model, outputPath) { return __awaiter(void 0, void
71
74
  beforeInsertion = fileContent.substring(0, closingBraceIndex);
72
75
  afterInsertion = fileContent.substring(closingBraceIndex);
73
76
  newContent = beforeInsertion + getAllTagsInterface + afterInsertion;
77
+ // 写入文件
74
78
  fs.writeFileSync(routerFilePath, newContent, 'utf-8');
75
79
  }
76
80
  console.log("\u2705 Tags \u529F\u80FD\u751F\u6210\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ".concat(modelsWithTags.length, " \u4E2A\u5305\u542B tags \u5B57\u6BB5\u7684\u6A21\u578B"));
77
81
  return [2 /*return*/];
78
82
  });
79
83
  }); };
80
- exports.generateTags = generateTags;
84
+ exports.generateTags = generateTags;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/next",
3
- "version": "0.3.23",
3
+ "version": "0.3.24",
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": "7fdb40c0c0b5fcccd0166722cd81e77df55885fb",
20
+ "gitHead": "82ce1f2a13a92943ae2618039c78148ff9637d52",
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  }