@zachacious/protoc-gen-connect-vue 1.0.16 → 1.0.17

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/generator.js CHANGED
@@ -336805,47 +336805,33 @@ var templates = {
336805
336805
  rpc: fs.readFileSync(path.join(templateDir, "rpc.ts.mustache"), "utf-8"),
336806
336806
  index: fs.readFileSync(path.join(templateDir, "index.ts.mustache"), "utf-8")
336807
336807
  };
336808
- function findBestPaginationCandidate(msg, isRequest, depth = 0) {
336808
+ function findPaginationPath(msg, isRequest, depth = 0) {
336809
336809
  if (depth > 3)
336810
336810
  return null;
336811
- let best = null;
336811
+ const reqKeywords = [
336812
+ "pagetoken",
336813
+ "pagenumber",
336814
+ "nextpagetoken",
336815
+ "offset",
336816
+ "cursor"
336817
+ ];
336818
+ const resKeywords = ["nextpagetoken", "nextpage", "nextcursor"];
336819
+ const targets = isRequest ? reqKeywords : resKeywords;
336820
+ for (const f of msg.fields) {
336821
+ const normalized = f.name.toLowerCase().replace(/_/g, "");
336822
+ if (targets.some((t) => normalized.includes(t)))
336823
+ return [f.name];
336824
+ if (isRequest && normalized === "page" && f.fieldKind === "message")
336825
+ return [f.name];
336826
+ }
336812
336827
  for (const f of msg.fields) {
336813
- let currentScore = 0;
336814
- const name = f.name.toLowerCase().replace(/_/g, "");
336815
- const reqKeywords = ["token", "page", "offset", "cursor", "start", "skip"];
336816
- const resKeywords = ["next", "token", "more", "hasmore", "cursor", "total"];
336817
- const targets = isRequest ? reqKeywords : resKeywords;
336818
- if (targets.some((t) => name.includes(t)))
336819
- currentScore += 10;
336820
- if (name.includes("pagetoken") || name.includes("nextpage"))
336821
- currentScore += 15;
336822
- const isString = f.fieldKind === "scalar" && f.scalar === 9;
336823
- const isNumber = f.fieldKind === "scalar" && [3, 4, 5, 13, 17, 18].includes(f.scalar);
336824
- if (isString || isNumber) {
336825
- currentScore += 5;
336826
- if (!best || currentScore > best.score) {
336827
- best = {
336828
- path: [f.name],
336829
- type: isString ? "string" : "number",
336830
- score: currentScore
336831
- };
336832
- }
336833
- }
336834
336828
  if (f.fieldKind === "message") {
336835
- const nested = findBestPaginationCandidate(f.message, isRequest, depth + 1);
336836
- if (nested) {
336837
- const nestedScore = nested.score + 12;
336838
- if (!best || nestedScore > best.score) {
336839
- best = {
336840
- path: [f.name, ...nested.path],
336841
- type: nested.type,
336842
- score: nestedScore
336843
- };
336844
- }
336845
- }
336829
+ const sub = findPaginationPath(f.message, isRequest, depth + 1);
336830
+ if (sub)
336831
+ return [f.name, ...sub];
336846
336832
  }
336847
336833
  }
336848
- return best;
336834
+ return null;
336849
336835
  }
336850
336836
  function processService(service) {
336851
336837
  const importMap = new Map;
@@ -336882,20 +336868,25 @@ function processService(service) {
336882
336868
  ];
336883
336869
  const isMutation = mutationVerbs.some((v) => name.startsWith(v));
336884
336870
  const isQuery = isUnary && !isMutation;
336885
- const reqCandidate = findBestPaginationCandidate(m.input, true);
336886
- const resCandidate = findBestPaginationCandidate(m.output, false);
336887
- const isPaginated = isQuery && reqCandidate && resCandidate && reqCandidate.score + resCandidate.score > 25;
336871
+ const reqPath = findPaginationPath(m.input, true);
336872
+ const resPath = findPaginationPath(m.output, false);
336873
+ const hasRepeatedList = m.output.fields.some((f) => {
336874
+ if (f.fieldKind === "map")
336875
+ return false;
336876
+ return f.repeated === true;
336877
+ });
336878
+ const isPaginated = isQuery && hasRepeatedList && !!reqPath && !!resPath;
336888
336879
  return {
336889
336880
  functionName: name.charAt(0).toLowerCase() + name.slice(1),
336890
336881
  hookName: `use${name}`,
336882
+ infiniteHookName: `use${name}Infinite`,
336891
336883
  resource: name.replace(/^(Get|ListAll|List|Search|Create|Update|Delete|Remove|Patch|Post|Set|Add)/, "") || "Global",
336892
336884
  inputType: m.input.name,
336893
336885
  outputType: m.output.name,
336894
336886
  isQuery,
336895
336887
  isPaginated,
336896
- reqPath: reqCandidate?.path.join("."),
336897
- resPath: resCandidate?.path.join("."),
336898
- pageType: reqCandidate?.type || "string"
336888
+ reqPath: reqPath?.join("."),
336889
+ resPath: resPath?.join(".")
336899
336890
  };
336900
336891
  });
336901
336892
  return {
@@ -336912,7 +336903,7 @@ function processService(service) {
336912
336903
  }
336913
336904
  var plugin = createEcmaScriptPlugin({
336914
336905
  name: "protoc-gen-connect-vue",
336915
- version: "v1.4.0",
336906
+ version: "v1.8.0",
336916
336907
  generateTs: (schema) => {
336917
336908
  const service = schema.files.flatMap((f) => f.services)[0];
336918
336909
  if (!service)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachacious/protoc-gen-connect-vue",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Smart TanStack Query & ConnectRPC SDK generator for Vue.js",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,6 +58,9 @@ export const useApi = () => {
58
58
  {{#rpcs}}
59
59
  {{functionName}},
60
60
  {{hookName}},
61
+ {{#isPaginated}}
62
+ {{infiniteHookName}},
63
+ {{/isPaginated}}
61
64
  {{/rpcs}}
62
65
  isGlobalLoading,
63
66
  queryKeys,
@@ -7,14 +7,29 @@ const {{functionName}} = async (req: {{inputType}}): Promise<APIResponse<{{outpu
7
7
  return res;
8
8
  };
9
9
 
10
+ {{#isQuery}}
10
11
  /**
11
- * Hook: {{hookName}}
12
+ * Standard Hook: {{hookName}}
12
13
  */
13
14
  const {{hookName}} = (
14
- {{#isQuery}}input: any, options: any = {}{{/isQuery}}
15
- {{^isQuery}}options: any = {}{{/isQuery}}
15
+ input: any,
16
+ options: any = {}
17
+ ) => {
18
+ return useQuery({
19
+ queryKey: queryKeys.{{functionName}}(input),
20
+ queryFn: () => client.value.{{functionName}}(unref(input)),
21
+ ...options,
22
+ });
23
+ };
24
+
25
+ {{#isPaginated}}
26
+ /**
27
+ * Infinite Hook: {{infiniteHookName}}
28
+ */
29
+ const {{infiniteHookName}} = (
30
+ input: any,
31
+ options: any = {}
16
32
  ) => {
17
- {{#isPaginated}}
18
33
  return useInfiniteQuery({
19
34
  queryKey: queryKeys.{{functionName}}(input),
20
35
  queryFn: async ({ pageParam }) => {
@@ -29,31 +44,28 @@ const {{hookName}} = (
29
44
  curr[path[path.length - 1]] = pageParam;
30
45
  return client.value.{{functionName}}(req);
31
46
  },
32
- initialPageParam: options.initialPageParam ?? ( "{{pageType}}" === "string" ? "" : 1 ),
47
+ initialPageParam: options.initialPageParam ?? "",
33
48
  getNextPageParam: (lastPage: any) => {
34
49
  const path = "{{resPath}}".split('.');
35
50
  const val = path.reduce((o, i) => o?.[i], lastPage);
36
-
37
- // If the discovered path is an object (like PageResponse), look for standard keys
38
51
  if (typeof val === 'object' && val !== null) {
39
- return val.nextPageToken || val.nextPage || val.pageToken || undefined;
52
+ return val.nextPageToken || val.nextPage || undefined;
40
53
  }
41
54
  return val || undefined;
42
55
  },
43
56
  ...options,
44
57
  });
45
- {{/isPaginated}}
46
-
47
- {{^isPaginated}}
48
- {{#isQuery}}
49
- return useQuery({
50
- queryKey: queryKeys.{{functionName}}(input),
51
- queryFn: () => client.value.{{functionName}}(unref(input)),
52
- ...options,
53
- });
54
- {{/isQuery}}
55
-
56
- {{^isQuery}}
58
+ };
59
+ {{/isPaginated}}
60
+ {{/isQuery}}
61
+
62
+ {{^isQuery}}
63
+ /**
64
+ * Mutation Hook: {{hookName}}
65
+ */
66
+ const {{hookName}} = (
67
+ options: any = {}
68
+ ) => {
57
69
  return useMutation({
58
70
  mutationFn: (req: {{inputType}}) => client.value.{{functionName}}(req),
59
71
  onSuccess: async (data, variables, context) => {
@@ -62,6 +74,5 @@ const {{hookName}} = (
62
74
  },
63
75
  ...options,
64
76
  });
65
- {{/isQuery}}
66
- {{/isPaginated}}
67
- };
77
+ };
78
+ {{/isQuery}}