@zachacious/protoc-gen-connect-vue 1.0.11 → 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 +23 -20
- package/package.json +1 -1
- package/templates/rpc.ts.mustache +15 -10
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 =
|
|
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
|
|
336810
|
-
if (depth >
|
|
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 =
|
|
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
|
|
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);
|
|
@@ -336844,8 +336843,9 @@ function processService(service) {
|
|
|
336844
336843
|
const rpcs = service.methods.map((m) => {
|
|
336845
336844
|
track(m.input);
|
|
336846
336845
|
track(m.output);
|
|
336846
|
+
const name = m.name;
|
|
336847
336847
|
const isUnary = m.methodKind === METHOD_KIND_UNARY;
|
|
336848
|
-
const
|
|
336848
|
+
const mutationVerbs = [
|
|
336849
336849
|
"Create",
|
|
336850
336850
|
"Update",
|
|
336851
336851
|
"Delete",
|
|
@@ -336855,28 +336855,31 @@ function processService(service) {
|
|
|
336855
336855
|
"Set",
|
|
336856
336856
|
"Add"
|
|
336857
336857
|
];
|
|
336858
|
-
const isMutation =
|
|
336859
|
-
const reqPath =
|
|
336858
|
+
const isMutation = mutationVerbs.some((v) => name.startsWith(v));
|
|
336859
|
+
const reqPath = findPaginationPath(m.input, [
|
|
336860
|
+
"pagenumber",
|
|
336860
336861
|
"page",
|
|
336861
336862
|
"offset",
|
|
336862
336863
|
"pagetoken",
|
|
336863
|
-
"cursor"
|
|
336864
|
-
"pagenumber"
|
|
336864
|
+
"cursor"
|
|
336865
336865
|
]);
|
|
336866
|
-
const resPath =
|
|
336866
|
+
const resPath = findPaginationPath(m.output, [
|
|
336867
336867
|
"nextpagetoken",
|
|
336868
336868
|
"nextpage",
|
|
336869
336869
|
"hasmore",
|
|
336870
|
-
"nextcursor"
|
|
336870
|
+
"nextcursor",
|
|
336871
|
+
"page"
|
|
336871
336872
|
]);
|
|
336873
|
+
const isQuery = isUnary && !isMutation;
|
|
336874
|
+
const isPaginated = isQuery && !!reqPath && !!resPath;
|
|
336872
336875
|
return {
|
|
336873
|
-
functionName:
|
|
336874
|
-
hookName: `use${
|
|
336875
|
-
resource:
|
|
336876
|
+
functionName: name.charAt(0).toLowerCase() + name.slice(1),
|
|
336877
|
+
hookName: `use${name}`,
|
|
336878
|
+
resource: name.replace(/^(Get|ListAll|List|Search|Create|Update|Delete|Remove|Patch|Post|Set|Add)/, "") || "Global",
|
|
336876
336879
|
inputType: m.input.name,
|
|
336877
336880
|
outputType: m.output.name,
|
|
336878
|
-
isQuery
|
|
336879
|
-
isPaginated
|
|
336881
|
+
isQuery,
|
|
336882
|
+
isPaginated,
|
|
336880
336883
|
reqPath: reqPath?.join("."),
|
|
336881
336884
|
resPath: resPath?.join(".")
|
|
336882
336885
|
};
|
|
@@ -336895,7 +336898,7 @@ function processService(service) {
|
|
|
336895
336898
|
}
|
|
336896
336899
|
var plugin = createEcmaScriptPlugin({
|
|
336897
336900
|
name: "protoc-gen-connect-vue",
|
|
336898
|
-
version: "v1.1.
|
|
336901
|
+
version: "v1.1.2",
|
|
336899
336902
|
generateTs: (schema) => {
|
|
336900
336903
|
const service = schema.files.flatMap((f) => f.services)[0];
|
|
336901
336904
|
if (!service)
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Async: {{functionName}}
|
|
2
|
+
* Async Wrapper: {{functionName}}
|
|
3
3
|
*/
|
|
4
4
|
const {{functionName}} = async (req: {{inputType}}): Promise<APIResponse<{{outputType}}>> => {
|
|
5
5
|
const res = await callConnect(client.value.{{functionName}}.bind(client.value), req, (res) => res);
|
|
@@ -25,25 +25,30 @@ const {{hookName}} = (
|
|
|
25
25
|
return useInfiniteQuery({
|
|
26
26
|
queryKey: queryKeys.{{functionName}}(input),
|
|
27
27
|
queryFn: async ({ pageParam }) => {
|
|
28
|
-
// Deep clone to avoid mutating reactive state
|
|
29
28
|
const req = JSON.parse(JSON.stringify(unref(input)));
|
|
30
|
-
|
|
31
|
-
// Structural Injection: Navigate to the field found during generation
|
|
32
29
|
const path = "{{reqPath}}".split('.');
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
// Navigate and set the nested pagination field
|
|
32
|
+
let curr = req;
|
|
34
33
|
for (let i = 0; i < path.length - 1; i++) {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
curr[path[i]] = curr[path[i]] || {};
|
|
35
|
+
curr = curr[path[i]];
|
|
37
36
|
}
|
|
38
|
-
|
|
37
|
+
curr[path[path.length - 1]] = pageParam;
|
|
39
38
|
|
|
40
39
|
return client.value.{{functionName}}(req);
|
|
41
40
|
},
|
|
42
41
|
initialPageParam: options.initialPageParam ?? 1,
|
|
43
42
|
getNextPageParam: (lastPage: any) => {
|
|
44
|
-
// Structural Extraction: Navigate to the field found during generation
|
|
45
43
|
const path = "{{resPath}}".split('.');
|
|
46
|
-
|
|
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;
|
|
47
52
|
},
|
|
48
53
|
...options,
|
|
49
54
|
});
|