@zachacious/protoc-gen-connect-vue 1.0.12 → 1.0.13

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
@@ -336792,7 +336792,7 @@ mustache.Writer = Writer;
336792
336792
  var mustache_default = mustache;
336793
336793
 
336794
336794
  // src/generator.ts
336795
- var METHOD_KIND_UNARY = 1;
336795
+ var METHOD_KIND_UNARY = 0;
336796
336796
  var KNOWN_WKT = [
336797
336797
  "google.protobuf.Empty",
336798
336798
  "google.protobuf.Timestamp",
@@ -336806,16 +336806,16 @@ var templates = {
336806
336806
  rpc: fs.readFileSync(path.join(templateDir, "rpc.ts.mustache"), "utf-8"),
336807
336807
  index: fs.readFileSync(path.join(templateDir, "index.ts.mustache"), "utf-8")
336808
336808
  };
336809
- function findPath(msg, targets, depth = 0) {
336810
- if (depth > 4)
336809
+ function findPaginationPath(msg, targets, depth = 0) {
336810
+ if (depth > 3)
336811
336811
  return null;
336812
336812
  for (const f of msg.fields) {
336813
- if (targets.includes(f.name.toLowerCase()))
336813
+ if (targets.includes(f.name.toLowerCase().replace(/_/g, "")))
336814
336814
  return [f.name];
336815
336815
  }
336816
336816
  for (const f of msg.fields) {
336817
336817
  if (f.fieldKind === "message") {
336818
- const p = findPath(f.message, targets, depth + 1);
336818
+ const p = findPaginationPath(f.message, targets, depth + 1);
336819
336819
  if (p)
336820
336820
  return [f.name, ...p];
336821
336821
  }
@@ -336834,8 +336834,7 @@ function processService(service) {
336834
336834
  if (allMessages.has(msg.name))
336835
336835
  return;
336836
336836
  allMessages.add(msg.name);
336837
- const baseFileName = msg.file.name.replace(".proto", "");
336838
- const importPath = `./gen/${baseFileName}_pb`;
336837
+ const importPath = `./gen/${msg.file.name.replace(".proto", "")}_pb`;
336839
336838
  if (!importMap.has(importPath))
336840
336839
  importMap.set(importPath, new Set);
336841
336840
  importMap.get(importPath).add(msg.name);
@@ -336857,18 +336856,19 @@ function processService(service) {
336857
336856
  "Add"
336858
336857
  ];
336859
336858
  const isMutation = mutationVerbs.some((v) => name.startsWith(v));
336860
- const reqPath = findPath(m.input, [
336859
+ const reqPath = findPaginationPath(m.input, [
336860
+ "pagenumber",
336861
336861
  "page",
336862
336862
  "offset",
336863
336863
  "pagetoken",
336864
- "cursor",
336865
- "pagenumber"
336864
+ "cursor"
336866
336865
  ]);
336867
- const resPath = findPath(m.output, [
336866
+ const resPath = findPaginationPath(m.output, [
336868
336867
  "nextpagetoken",
336869
336868
  "nextpage",
336870
336869
  "hasmore",
336871
- "nextcursor"
336870
+ "nextcursor",
336871
+ "page"
336872
336872
  ]);
336873
336873
  const isQuery = isUnary && !isMutation;
336874
336874
  const isPaginated = isQuery && !!reqPath && !!resPath;
@@ -336898,7 +336898,7 @@ function processService(service) {
336898
336898
  }
336899
336899
  var plugin = createEcmaScriptPlugin({
336900
336900
  name: "protoc-gen-connect-vue",
336901
- version: "v1.1.1",
336901
+ version: "v1.1.2",
336902
336902
  generateTs: (schema) => {
336903
336903
  const service = schema.files.flatMap((f) => f.services)[0];
336904
336904
  if (!service)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachacious/protoc-gen-connect-vue",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Smart TanStack Query & ConnectRPC SDK generator for Vue.js",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@ const {{functionName}} = async (req: {{inputType}}): Promise<APIResponse<{{outpu
14
14
  */
15
15
  const {{hookName}} = (
16
16
  {{#isQuery}}
17
- input: any, // Accepts Ref<{{inputType}}> or {{inputType}}
17
+ input: any,
18
18
  options: any = {}
19
19
  {{/isQuery}}
20
20
  {{^isQuery}}
@@ -25,22 +25,30 @@ const {{hookName}} = (
25
25
  return useInfiniteQuery({
26
26
  queryKey: queryKeys.{{functionName}}(input),
27
27
  queryFn: async ({ pageParam }) => {
28
- // Safely inject pageParam into the discovered path
29
28
  const req = JSON.parse(JSON.stringify(unref(input)));
30
29
  const path = "{{reqPath}}".split('.');
31
- let current = req;
30
+
31
+ // Navigate and set the nested pagination field
32
+ let curr = req;
32
33
  for (let i = 0; i < path.length - 1; i++) {
33
- if (!current[path[i]]) current[path[i]] = {};
34
- current = current[path[i]];
34
+ curr[path[i]] = curr[path[i]] || {};
35
+ curr = curr[path[i]];
35
36
  }
36
- current[path[path.length - 1]] = pageParam;
37
+ curr[path[path.length - 1]] = pageParam;
37
38
 
38
39
  return client.value.{{functionName}}(req);
39
40
  },
40
41
  initialPageParam: options.initialPageParam ?? 1,
41
42
  getNextPageParam: (lastPage: any) => {
42
43
  const path = "{{resPath}}".split('.');
43
- return path.reduce((o, i) => o?.[i], lastPage) || undefined;
44
+ // Traverse response to find next page/token (handles nested PageResponse)
45
+ const nextValue = path.reduce((o, i) => o?.[i], lastPage);
46
+
47
+ // If the nextValue is an object (like PageResponse), we look deeper
48
+ if (typeof nextValue === 'object' && nextValue !== null) {
49
+ return nextValue.nextPageToken || nextValue.nextPage || nextValue.pageNumber + 1;
50
+ }
51
+ return nextValue || undefined;
44
52
  },
45
53
  ...options,
46
54
  });