@zachacious/protoc-gen-connect-vue 1.0.13 → 1.0.15
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 +11 -22
- package/package.json +1 -1
- package/templates/rpc.ts.mustache +10 -9
package/dist/generator.js
CHANGED
|
@@ -336792,7 +336792,6 @@ mustache.Writer = Writer;
|
|
|
336792
336792
|
var mustache_default = mustache;
|
|
336793
336793
|
|
|
336794
336794
|
// src/generator.ts
|
|
336795
|
-
var METHOD_KIND_UNARY = 0;
|
|
336796
336795
|
var KNOWN_WKT = [
|
|
336797
336796
|
"google.protobuf.Empty",
|
|
336798
336797
|
"google.protobuf.Timestamp",
|
|
@@ -336806,18 +336805,20 @@ var templates = {
|
|
|
336806
336805
|
rpc: fs.readFileSync(path.join(templateDir, "rpc.ts.mustache"), "utf-8"),
|
|
336807
336806
|
index: fs.readFileSync(path.join(templateDir, "index.ts.mustache"), "utf-8")
|
|
336808
336807
|
};
|
|
336809
|
-
function findPaginationPath(msg,
|
|
336808
|
+
function findPaginationPath(msg, depth = 0) {
|
|
336810
336809
|
if (depth > 3)
|
|
336811
336810
|
return null;
|
|
336811
|
+
const targets = ["pagenumber", "offset", "pagetoken", "cursor"];
|
|
336812
336812
|
for (const f of msg.fields) {
|
|
336813
|
-
|
|
336813
|
+
const normalized = f.name.toLowerCase().replace(/_/g, "");
|
|
336814
|
+
if (targets.includes(normalized))
|
|
336814
336815
|
return [f.name];
|
|
336815
336816
|
}
|
|
336816
336817
|
for (const f of msg.fields) {
|
|
336817
336818
|
if (f.fieldKind === "message") {
|
|
336818
|
-
const
|
|
336819
|
-
if (
|
|
336820
|
-
return [f.name, ...
|
|
336819
|
+
const subPath = findPaginationPath(f.message, depth + 1);
|
|
336820
|
+
if (subPath)
|
|
336821
|
+
return [f.name, ...subPath];
|
|
336821
336822
|
}
|
|
336822
336823
|
}
|
|
336823
336824
|
return null;
|
|
@@ -336844,7 +336845,7 @@ function processService(service) {
|
|
|
336844
336845
|
track(m.input);
|
|
336845
336846
|
track(m.output);
|
|
336846
336847
|
const name = m.name;
|
|
336847
|
-
const isUnary = m.methodKind ===
|
|
336848
|
+
const isUnary = m.methodKind === "unary";
|
|
336848
336849
|
const mutationVerbs = [
|
|
336849
336850
|
"Create",
|
|
336850
336851
|
"Update",
|
|
@@ -336856,21 +336857,9 @@ function processService(service) {
|
|
|
336856
336857
|
"Add"
|
|
336857
336858
|
];
|
|
336858
336859
|
const isMutation = mutationVerbs.some((v) => name.startsWith(v));
|
|
336859
|
-
const reqPath = findPaginationPath(m.input, [
|
|
336860
|
-
"pagenumber",
|
|
336861
|
-
"page",
|
|
336862
|
-
"offset",
|
|
336863
|
-
"pagetoken",
|
|
336864
|
-
"cursor"
|
|
336865
|
-
]);
|
|
336866
|
-
const resPath = findPaginationPath(m.output, [
|
|
336867
|
-
"nextpagetoken",
|
|
336868
|
-
"nextpage",
|
|
336869
|
-
"hasmore",
|
|
336870
|
-
"nextcursor",
|
|
336871
|
-
"page"
|
|
336872
|
-
]);
|
|
336873
336860
|
const isQuery = isUnary && !isMutation;
|
|
336861
|
+
const reqPath = findPaginationPath(m.input);
|
|
336862
|
+
const resPath = findPaginationPath(m.output);
|
|
336874
336863
|
const isPaginated = isQuery && !!reqPath && !!resPath;
|
|
336875
336864
|
return {
|
|
336876
336865
|
functionName: name.charAt(0).toLowerCase() + name.slice(1),
|
|
@@ -336898,7 +336887,7 @@ function processService(service) {
|
|
|
336898
336887
|
}
|
|
336899
336888
|
var plugin = createEcmaScriptPlugin({
|
|
336900
336889
|
name: "protoc-gen-connect-vue",
|
|
336901
|
-
version: "v1.1
|
|
336890
|
+
version: "v1.2.1",
|
|
336902
336891
|
generateTs: (schema) => {
|
|
336903
336892
|
const service = schema.files.flatMap((f) => f.services)[0];
|
|
336904
336893
|
if (!service)
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Async
|
|
2
|
+
* Async Action: {{functionName}}
|
|
3
|
+
* Manual execution outside of the reactive cycle.
|
|
3
4
|
*/
|
|
4
5
|
const {{functionName}} = async (req: {{inputType}}): Promise<APIResponse<{{outputType}}>> => {
|
|
5
6
|
const res = await callConnect(client.value.{{functionName}}.bind(client.value), req, (res) => res);
|
|
@@ -10,7 +11,8 @@ const {{functionName}} = async (req: {{inputType}}): Promise<APIResponse<{{outpu
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* Hook: {{hookName}}
|
|
14
|
+
* TanStack Hook: {{hookName}}
|
|
15
|
+
* Reactive hook for Vue components.
|
|
14
16
|
*/
|
|
15
17
|
const {{hookName}} = (
|
|
16
18
|
{{#isQuery}}
|
|
@@ -25,10 +27,10 @@ const {{hookName}} = (
|
|
|
25
27
|
return useInfiniteQuery({
|
|
26
28
|
queryKey: queryKeys.{{functionName}}(input),
|
|
27
29
|
queryFn: async ({ pageParam }) => {
|
|
30
|
+
// Deep clone to safely inject pageParam
|
|
28
31
|
const req = JSON.parse(JSON.stringify(unref(input)));
|
|
29
32
|
const path = "{{reqPath}}".split('.');
|
|
30
33
|
|
|
31
|
-
// Navigate and set the nested pagination field
|
|
32
34
|
let curr = req;
|
|
33
35
|
for (let i = 0; i < path.length - 1; i++) {
|
|
34
36
|
curr[path[i]] = curr[path[i]] || {};
|
|
@@ -41,14 +43,13 @@ const {{hookName}} = (
|
|
|
41
43
|
initialPageParam: options.initialPageParam ?? 1,
|
|
42
44
|
getNextPageParam: (lastPage: any) => {
|
|
43
45
|
const path = "{{resPath}}".split('.');
|
|
44
|
-
|
|
45
|
-
const nextValue = path.reduce((o, i) => o?.[i], lastPage);
|
|
46
|
+
const val = path.reduce((o, i) => o?.[i], lastPage);
|
|
46
47
|
|
|
47
|
-
//
|
|
48
|
-
if (typeof
|
|
49
|
-
return
|
|
48
|
+
// Structural Extraction: handle common field names or objects
|
|
49
|
+
if (typeof val === 'object' && val !== null) {
|
|
50
|
+
return val.nextPageToken || val.nextPage || (val.pageNumber ? val.pageNumber + 1 : undefined);
|
|
50
51
|
}
|
|
51
|
-
return
|
|
52
|
+
return val || undefined;
|
|
52
53
|
},
|
|
53
54
|
...options,
|
|
54
55
|
});
|