@zachacious/protoc-gen-connect-vue 1.0.2 โ 1.0.5
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/README.md +210 -2
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -1,2 +1,210 @@
|
|
|
1
|
-
# protoc-gen-connect-vue
|
|
2
|
-
|
|
1
|
+
# **@zachacious/protoc-gen-connect-vue**
|
|
2
|
+
|
|
3
|
+
A specialized protoc plugin designed to generate a production-grade, reactive TypeScript SDK for **Vue.js**. This plugin serves as an intelligent orchestration layer on top of [ConnectRPC](https://connectrpc.com/) and [TanStack Vue Query](https://tanstack.com/query/latest), automating the tedious aspects of state management, cache synchronization, and pagination.
|
|
4
|
+
|
|
5
|
+
## **๐ Context & Architecture**
|
|
6
|
+
|
|
7
|
+
This project is not a replacement for standard tooling but an enhancement of it. It leverages the official [connect-query-es](https://github.com/connectrpc/connect-query-es) plugin to generate underlying query definitions and wraps them in a high-level SDK tailored for Vue 3.
|
|
8
|
+
|
|
9
|
+
### **Core Pillars**
|
|
10
|
+
|
|
11
|
+
1. **Reactivity:** Deep integration with Vue's Composition API.
|
|
12
|
+
2. **Smart Invalidation:** Heuristic-based cache clearing. When a mutation (e.g., CreateTicket) succeeds, the SDK automatically invalidates related queries (e.g., ListTickets).
|
|
13
|
+
3. **Deep Pagination Search:** Recursively scans Protobuf messages for pagination fields to automatically switch from standard useQuery to useInfiniteQuery.
|
|
14
|
+
4. **Transport Decoupling:** Global interceptors for Auth and Error handling so your components stay clean.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## **๐ Installation**
|
|
19
|
+
|
|
20
|
+
### **1. Plugin Installation**
|
|
21
|
+
|
|
22
|
+
You can install the plugin globally or as a dev dependency.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
# Recommended for local development
|
|
26
|
+
npm install --save-dev @zachacious/protoc-gen-connect-vue
|
|
27
|
+
|
|
28
|
+
# For use across non-Node projects (Go/Rust/etc)
|
|
29
|
+
npm install -g @zachacious/protoc-gen-connect-vue
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### **2. Peer Dependencies**
|
|
33
|
+
|
|
34
|
+
The generated SDK requires these specific packages to be installed in your Vue project:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
npm install @connectrpc/connect @connectrpc/connect-web @connectrpc/connect-query @tanstack/vue-query @bufbuild/protobuf
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## **โ๏ธ Configuration**
|
|
43
|
+
|
|
44
|
+
### **buf.gen.yaml**
|
|
45
|
+
|
|
46
|
+
The plugin **must** run after protoc-gen-es and protoc-gen-connect-query.
|
|
47
|
+
|
|
48
|
+
```yaml
|
|
49
|
+
version: v2
|
|
50
|
+
managed:
|
|
51
|
+
enabled: true
|
|
52
|
+
plugins:
|
|
53
|
+
# 1. Base Protobuf TS messages
|
|
54
|
+
- local: es
|
|
55
|
+
out: gen
|
|
56
|
+
opt: target=ts
|
|
57
|
+
# 2. ConnectRPC Query definitions
|
|
58
|
+
- local: connect-query
|
|
59
|
+
out: gen
|
|
60
|
+
opt: target=ts
|
|
61
|
+
# 3. Smart SDK Generator
|
|
62
|
+
- local: protoc-gen-connect-vue
|
|
63
|
+
out: src/api
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
**๐ Integration & Setup**
|
|
69
|
+
|
|
70
|
+
### **1. Global Client Configuration (main.ts)**
|
|
71
|
+
|
|
72
|
+
Configure your environment-specific settings before mounting the app.
|
|
73
|
+
|
|
74
|
+
```TypeScript
|
|
75
|
+
|
|
76
|
+
import { createApp } from 'vue';
|
|
77
|
+
import { VueQueryPlugin } from '@tanstack/vue-query';
|
|
78
|
+
import { setBaseUrl, setAuthResolver, setSDKErrorCallback, globalQueryConfig } from '@/api';
|
|
79
|
+
import { useAuthStore } from '@/stores/auth';
|
|
80
|
+
|
|
81
|
+
const app = createApp(App);
|
|
82
|
+
|
|
83
|
+
// 1. Initialize TanStack with SDK defaults (StaleTime, GC, etc.)
|
|
84
|
+
app.use(VueQueryPlugin, { queryClientConfig: globalQueryConfig });
|
|
85
|
+
|
|
86
|
+
// 2. Configure Endpoint
|
|
87
|
+
setBaseUrl(import.meta.env.VITE_API_URL);
|
|
88
|
+
|
|
89
|
+
// 3. Setup Auth Bridge (Decoupled from SDK logic)
|
|
90
|
+
const auth = useAuthStore();
|
|
91
|
+
setAuthResolver(async () => {
|
|
92
|
+
return auth.token; // Header 'x-api-key' added if exists
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// 4. Global Error Handling
|
|
96
|
+
setSDKErrorCallback((err, url) => {
|
|
97
|
+
if (err.code === 16) { // Unauthenticated
|
|
98
|
+
auth.logout();
|
|
99
|
+
window.location.href = '/login';
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
app.mount('#app');
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### **2. Transport Provider Setup (App.vue)**
|
|
107
|
+
|
|
108
|
+
You must wrap your application (or relevant route views) in the TransportProvider to provide the ConnectRPC context to the hooks.
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<script setup lang="ts">
|
|
112
|
+
import { TransportProvider } from "@connectrpc/connect-query";
|
|
113
|
+
import { transport } from "@/api/client";
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<template>
|
|
117
|
+
<TransportProvider :transport="transport">
|
|
118
|
+
<router-view />
|
|
119
|
+
</TransportProvider>
|
|
120
|
+
</template>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## **๐ Usage Examples**
|
|
126
|
+
|
|
127
|
+
### **Reactive Queries**
|
|
128
|
+
|
|
129
|
+
Unary RPCs that don't start with mutation verbs are generated as standard queries.
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<script setup lang="ts">
|
|
133
|
+
import { useApi } from "@/api";
|
|
134
|
+
const api = useApi();
|
|
135
|
+
|
|
136
|
+
const { data, isLoading } = api.useGetCustomerById({ id: "123" });
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<template>
|
|
140
|
+
<div v-if="isLoading">Loading...</div>
|
|
141
|
+
<div v-else>{{ data.name }}</div>
|
|
142
|
+
</template>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### **Automated Mutations & Invalidation**
|
|
146
|
+
|
|
147
|
+
The SDK uses resource-name stripping (e.g., UpdateTicket -> Ticket) to invalidate active lists automatically.
|
|
148
|
+
|
|
149
|
+
```html
|
|
150
|
+
<script setup lang="ts">
|
|
151
|
+
const { mutate, isPending } = api.useUpdateTicket({
|
|
152
|
+
onSuccess: () => console.log("List refreshed by SDK!"),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const save = () => mutate({ id: "123", status: "CLOSED" });
|
|
156
|
+
</script>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### **Infinite Scrolling (Pagination)**
|
|
160
|
+
|
|
161
|
+
If fields like page, offset, or limit are detected, the SDK generates an InfiniteQuery.
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
<script setup lang="ts">
|
|
165
|
+
const { data, fetchNextPage, hasNextPage } = api.useListTickets({
|
|
166
|
+
filter: "open",
|
|
167
|
+
});
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<template>
|
|
171
|
+
<div v-for="page in data?.pages">
|
|
172
|
+
<div v-for="ticket in page.items">{{ ticket.subject }}</div>
|
|
173
|
+
</div>
|
|
174
|
+
<button v-if="hasNextPage" @click="fetchNextPage">Load More</button>
|
|
175
|
+
</template>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## **๐งช Advanced Features**
|
|
181
|
+
|
|
182
|
+
### **Global Loading State**
|
|
183
|
+
|
|
184
|
+
Track the status of _every_ RPC call in your application via a single computed property.
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<script setup lang="ts">
|
|
188
|
+
const { isGlobalLoading } = useApi();
|
|
189
|
+
</script>
|
|
190
|
+
|
|
191
|
+
<template>
|
|
192
|
+
<ProgressBar v-if="isGlobalLoading" />
|
|
193
|
+
</template>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### **Protobuf Documentation Tags**
|
|
197
|
+
|
|
198
|
+
Fine-tune your SDK directly from your .proto comments:
|
|
199
|
+
|
|
200
|
+
| Tag | Description |
|
|
201
|
+
| :------------------- | :--------------------------------------------------------------- |
|
|
202
|
+
| @wrapper:auth | Marks the endpoint as expecting authentication in documentation. |
|
|
203
|
+
| @sdk:signature=(...) | Overrides the generated TypeScript function signature. |
|
|
204
|
+
| @sdk:data=res.item | Overrides the default data extractor for async wrappers. |
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
**๐ License**
|
|
209
|
+
|
|
210
|
+
MIT ยฉ [Zachacious](https://www.google.com/search?q=https://github.com/zachacious)
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zachacious/protoc-gen-connect-vue",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Smart TanStack Query & ConnectRPC SDK generator for Vue.js",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Zachacious",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/zachacious/protoc-gen-connect-vue.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/zachacious/protoc-gen-connect-vue/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/zachacious/protoc-gen-connect-vue#readme",
|
|
6
16
|
"main": "dist/generator.js",
|
|
7
17
|
"bin": {
|
|
8
18
|
"protoc-gen-connect-vue": "bin/protoc-gen-connect-vue"
|
|
@@ -10,7 +20,9 @@
|
|
|
10
20
|
"files": [
|
|
11
21
|
"dist",
|
|
12
22
|
"bin",
|
|
13
|
-
"templates"
|
|
23
|
+
"templates",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
14
26
|
],
|
|
15
27
|
"publishConfig": {
|
|
16
28
|
"access": "public"
|