@tthr/vue 0.0.69 → 0.0.71
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/server.d.ts.map +1 -1
- package/dist/server.js +20 -7
- package/dist/server.js.map +1 -1
- package/nuxt/runtime/server/mutation.post.js +6 -4
- package/nuxt/runtime/server/query.post.js +6 -4
- package/package.json +1 -1
- package/nuxt/runtime/composables.d.ts +0 -87
- package/nuxt/runtime/composables.js +0 -275
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,EAAgC,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGtG,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAKlF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAE9E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAQpD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CAEzF;AAMD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,eAAe,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,C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EAAE,OAAO,EAClD,EAAE,EAAE,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,EACxE,IAAI,EAAE,KAAK,EACX,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,OAAO,CAAC,CA4ClB"}
|
package/dist/server.js
CHANGED
|
@@ -152,12 +152,17 @@ function createDatabaseProxy(client) {
|
|
|
152
152
|
},
|
|
153
153
|
upsert: async (options) => {
|
|
154
154
|
const whereObj = options.where;
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
// Try to find existing record using the where clause
|
|
156
|
+
// This allows upserting on any field (e.g. clip_id, email, etc.)
|
|
157
|
+
// Use list with limit: 1 since findFirst doesn't exist on the server
|
|
158
|
+
const results = await client.query(`${tableName}.list`, { where: whereObj, limit: 1 }).catch(() => []);
|
|
159
|
+
const existing = results?.[0] ?? null;
|
|
160
160
|
if (existing) {
|
|
161
|
+
// Use _id from the found record for the update
|
|
162
|
+
const id = existing._id ?? existing.id;
|
|
163
|
+
if (!id) {
|
|
164
|
+
throw new Error('Found record has no _id or id field for update');
|
|
165
|
+
}
|
|
161
166
|
await client.mutation(`${tableName}.update`, { id, data: options.update });
|
|
162
167
|
return { ...existing, ...options.update };
|
|
163
168
|
}
|
|
@@ -167,13 +172,21 @@ function createDatabaseProxy(client) {
|
|
|
167
172
|
},
|
|
168
173
|
delete: async (options) => {
|
|
169
174
|
const whereObj = options.where;
|
|
170
|
-
const id = whereObj.id;
|
|
175
|
+
const id = whereObj._id ?? whereObj.id;
|
|
171
176
|
if (!id) {
|
|
172
|
-
throw new Error('Delete requires an id in the where clause');
|
|
177
|
+
throw new Error('Delete requires an _id or id in the where clause');
|
|
173
178
|
}
|
|
174
179
|
const result = await client.mutation(`${tableName}.delete`, { id });
|
|
175
180
|
return result?.rowsAffected ?? 0;
|
|
176
181
|
},
|
|
182
|
+
deleteMany: async (options) => {
|
|
183
|
+
const result = await client.mutation(`${tableName}.deleteMany`, { where: options.where });
|
|
184
|
+
return result?.rowsAffected ?? 0;
|
|
185
|
+
},
|
|
186
|
+
deleteAll: async () => {
|
|
187
|
+
const result = await client.mutation(`${tableName}.deleteAll`, {});
|
|
188
|
+
return result?.rowsAffected ?? 0;
|
|
189
|
+
},
|
|
177
190
|
deleteById: async (id) => {
|
|
178
191
|
const result = await client.mutation(`${tableName}.delete`, { id });
|
|
179
192
|
return (result?.rowsAffected ?? 0) > 0;
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,kBAAkB,EAAkC,MAAM,cAAc,CAAC;AAGlF,wDAAwD;AACxD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,cAAc,CAAC;AAElF,4BAA4B;AAC5B,IAAI,YAAY,GAA8B,IAAI,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAkC;IACtE,YAAY,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2EAA2E;YAC3E,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAwCD;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAA0B;IACrD,OAAO,IAAI,KAAK,CAAC,EAAoB,EAAE;QACrC,GAAG,CAAC,OAAO,EAAE,SAA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IACrC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;IAC9C,IAAI,QAAQ,EAAE,CAAC;QACb,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC;QAC9B,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC;QACnC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,wBAAwB;IACxB,MAAM,cAAc,GAAG;QACrB,EAAE;QACF,GAAG;QACH,IAAI;QACJ,IAAI;KACL,CAAC;IAEF,+BAA+B;IAC/B,yEAAyE;IACzE,8DAA8D;IAC9D,OAAO,EAAE,CAAC,OAAO,CAAC,cAAqB,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -185,9 +185,10 @@ function createDatabaseProxy(apiKey, url, projectId) {
|
|
|
185
185
|
},
|
|
186
186
|
update: async (options) => {
|
|
187
187
|
const whereObj = options.where;
|
|
188
|
-
|
|
188
|
+
// Support both _id (standard) and id (legacy) in where clause
|
|
189
|
+
const id = whereObj?._id ?? whereObj?.id;
|
|
189
190
|
if (!id) {
|
|
190
|
-
throw new Error('Update requires an
|
|
191
|
+
throw new Error('Update requires an _id in the where clause');
|
|
191
192
|
}
|
|
192
193
|
const result = await makeMutation('update', { id, data: options.data });
|
|
193
194
|
return result?.rowsAffected ?? 0;
|
|
@@ -215,9 +216,10 @@ function createDatabaseProxy(apiKey, url, projectId) {
|
|
|
215
216
|
},
|
|
216
217
|
delete: async (options) => {
|
|
217
218
|
const whereObj = options.where;
|
|
218
|
-
|
|
219
|
+
// Support both _id (standard) and id (legacy) in where clause
|
|
220
|
+
const id = whereObj?._id ?? whereObj?.id;
|
|
219
221
|
if (!id) {
|
|
220
|
-
throw new Error('Delete requires an
|
|
222
|
+
throw new Error('Delete requires an _id in the where clause');
|
|
221
223
|
}
|
|
222
224
|
const result = await makeMutation('delete', { id });
|
|
223
225
|
return result?.rowsAffected ?? 0;
|
|
@@ -185,9 +185,10 @@ function createDatabaseProxy(apiKey, url, projectId) {
|
|
|
185
185
|
},
|
|
186
186
|
update: async (options) => {
|
|
187
187
|
const whereObj = options.where;
|
|
188
|
-
|
|
188
|
+
// Support both _id (standard) and id (legacy) in where clause
|
|
189
|
+
const id = whereObj?._id ?? whereObj?.id;
|
|
189
190
|
if (!id) {
|
|
190
|
-
throw new Error('Update requires an
|
|
191
|
+
throw new Error('Update requires an _id in the where clause');
|
|
191
192
|
}
|
|
192
193
|
const result = await makeMutation('update', { id, data: options.data });
|
|
193
194
|
return result?.rowsAffected ?? 0;
|
|
@@ -215,9 +216,10 @@ function createDatabaseProxy(apiKey, url, projectId) {
|
|
|
215
216
|
},
|
|
216
217
|
delete: async (options) => {
|
|
217
218
|
const whereObj = options.where;
|
|
218
|
-
|
|
219
|
+
// Support both _id (standard) and id (legacy) in where clause
|
|
220
|
+
const id = whereObj?._id ?? whereObj?.id;
|
|
219
221
|
if (!id) {
|
|
220
|
-
throw new Error('Delete requires an
|
|
222
|
+
throw new Error('Delete requires an _id in the where clause');
|
|
221
223
|
}
|
|
222
224
|
const result = await makeMutation('delete', { id });
|
|
223
225
|
return result?.rowsAffected ?? 0;
|
package/package.json
CHANGED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nuxt composables for Tether
|
|
3
|
-
*
|
|
4
|
-
* These are auto-imported when using the Tether Nuxt module.
|
|
5
|
-
* Queries and mutations are executed server-side to keep API keys secure.
|
|
6
|
-
* WebSocket subscriptions run client-side for realtime updates.
|
|
7
|
-
*/
|
|
8
|
-
import { type Ref } from 'vue';
|
|
9
|
-
/**
|
|
10
|
-
* Query state returned by useQuery
|
|
11
|
-
*/
|
|
12
|
-
export interface QueryState<T> {
|
|
13
|
-
data: Ref<T | undefined>;
|
|
14
|
-
error: Ref<Error | null>;
|
|
15
|
-
isLoading: Ref<boolean>;
|
|
16
|
-
refetch: () => Promise<void>;
|
|
17
|
-
/** Update data directly (used for hot-swapping from WebSocket) */
|
|
18
|
-
setData: (newData: T) => void;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Query function reference
|
|
22
|
-
*/
|
|
23
|
-
export interface QueryFunction<TArgs = void, TResult = unknown> {
|
|
24
|
-
_name: string;
|
|
25
|
-
_args?: TArgs;
|
|
26
|
-
_result?: TResult;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Reactive query composable with auto-refresh on subscription updates
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```vue
|
|
33
|
-
* <script setup>
|
|
34
|
-
* const { data: posts, isLoading } = useQuery(api.posts.list);
|
|
35
|
-
* </script>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function useQuery<TArgs, TResult>(query: QueryFunction<TArgs, TResult> | string, args?: TArgs): QueryState<TResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Mutation state returned by useMutation
|
|
41
|
-
*/
|
|
42
|
-
export interface MutationState<TArgs, TResult> {
|
|
43
|
-
data: Ref<TResult | undefined>;
|
|
44
|
-
error: Ref<Error | null>;
|
|
45
|
-
isPending: Ref<boolean>;
|
|
46
|
-
mutate: (args: TArgs) => Promise<TResult>;
|
|
47
|
-
reset: () => void;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Mutation function reference
|
|
51
|
-
*/
|
|
52
|
-
export interface MutationFunction<TArgs = void, TResult = unknown> {
|
|
53
|
-
_name: string;
|
|
54
|
-
_args?: TArgs;
|
|
55
|
-
_result?: TResult;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Mutation composable
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```vue
|
|
62
|
-
* <script setup>
|
|
63
|
-
* const { mutate: createPost, isPending } = useMutation(api.posts.create);
|
|
64
|
-
*
|
|
65
|
-
* async function handleSubmit() {
|
|
66
|
-
* await createPost({ title: 'Hello', content: '...' });
|
|
67
|
-
* }
|
|
68
|
-
* </script>
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare function useMutation<TArgs, TResult>(mutation: MutationFunction<TArgs, TResult> | string): MutationState<TArgs, TResult>;
|
|
72
|
-
/**
|
|
73
|
-
* WebSocket subscription composable for realtime updates
|
|
74
|
-
* This runs client-side only and calls refetch when updates are received
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```vue
|
|
78
|
-
* <script setup>
|
|
79
|
-
* const { data: posts, refetch } = useQuery('posts.list');
|
|
80
|
-
* useTetherSubscription('posts.list', {}, refetch);
|
|
81
|
-
* </script>
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
export declare function useTetherSubscription(queryName: string, args: Record<string, unknown> | undefined, onUpdate: (data?: unknown) => void): {
|
|
85
|
-
isConnected: Ref<boolean>;
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=composables.d.ts.map
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nuxt composables for Tether
|
|
3
|
-
*
|
|
4
|
-
* These are auto-imported when using the Tether Nuxt module.
|
|
5
|
-
* Queries and mutations are executed server-side to keep API keys secure.
|
|
6
|
-
* WebSocket subscriptions run client-side for realtime updates.
|
|
7
|
-
*/
|
|
8
|
-
import { ref, onMounted, onUnmounted } from 'vue';
|
|
9
|
-
/**
|
|
10
|
-
* Reactive query composable with auto-refresh on subscription updates
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```vue
|
|
14
|
-
* <script setup>
|
|
15
|
-
* const { data: posts, isLoading } = useQuery(api.posts.list);
|
|
16
|
-
* </script>
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export function useQuery(query, args) {
|
|
20
|
-
const queryName = typeof query === 'string' ? query : query._name;
|
|
21
|
-
const data = ref();
|
|
22
|
-
const error = ref(null);
|
|
23
|
-
const isLoading = ref(true);
|
|
24
|
-
const fetchData = async () => {
|
|
25
|
-
try {
|
|
26
|
-
isLoading.value = true;
|
|
27
|
-
error.value = null;
|
|
28
|
-
const response = await $fetch('/api/_tether/query', {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
body: {
|
|
31
|
-
function: queryName,
|
|
32
|
-
args,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
data.value = response.data;
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
error.value = e instanceof Error ? e : new Error(String(e));
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
isLoading.value = false;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
// Fetch on mount (client-side)
|
|
45
|
-
onMounted(() => {
|
|
46
|
-
fetchData();
|
|
47
|
-
});
|
|
48
|
-
// Also fetch immediately for SSR
|
|
49
|
-
if (import.meta.server) {
|
|
50
|
-
fetchData();
|
|
51
|
-
}
|
|
52
|
-
// Direct data setter for hot-swapping from WebSocket
|
|
53
|
-
const setData = (newData) => {
|
|
54
|
-
data.value = newData;
|
|
55
|
-
};
|
|
56
|
-
return {
|
|
57
|
-
data: data,
|
|
58
|
-
error,
|
|
59
|
-
isLoading,
|
|
60
|
-
refetch: fetchData,
|
|
61
|
-
setData,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Mutation composable
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```vue
|
|
69
|
-
* <script setup>
|
|
70
|
-
* const { mutate: createPost, isPending } = useMutation(api.posts.create);
|
|
71
|
-
*
|
|
72
|
-
* async function handleSubmit() {
|
|
73
|
-
* await createPost({ title: 'Hello', content: '...' });
|
|
74
|
-
* }
|
|
75
|
-
* </script>
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export function useMutation(mutation) {
|
|
79
|
-
const mutationName = typeof mutation === 'string' ? mutation : mutation._name;
|
|
80
|
-
const data = ref();
|
|
81
|
-
const error = ref(null);
|
|
82
|
-
const isPending = ref(false);
|
|
83
|
-
const mutate = async (args) => {
|
|
84
|
-
try {
|
|
85
|
-
isPending.value = true;
|
|
86
|
-
error.value = null;
|
|
87
|
-
const response = await $fetch('/api/_tether/mutation', {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
body: {
|
|
90
|
-
function: mutationName,
|
|
91
|
-
args,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
data.value = response.data;
|
|
95
|
-
return response.data;
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
error.value = e instanceof Error ? e : new Error(String(e));
|
|
99
|
-
throw e;
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
isPending.value = false;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const reset = () => {
|
|
106
|
-
data.value = undefined;
|
|
107
|
-
error.value = null;
|
|
108
|
-
isPending.value = false;
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
data: data,
|
|
112
|
-
error,
|
|
113
|
-
isPending,
|
|
114
|
-
mutate,
|
|
115
|
-
reset,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* WebSocket subscription composable for realtime updates
|
|
120
|
-
* This runs client-side only and calls refetch when updates are received
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```vue
|
|
124
|
-
* <script setup>
|
|
125
|
-
* const { data: posts, refetch } = useQuery('posts.list');
|
|
126
|
-
* useTetherSubscription('posts.list', {}, refetch);
|
|
127
|
-
* </script>
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
export function useTetherSubscription(queryName, args, onUpdate) {
|
|
131
|
-
const isConnected = ref(false);
|
|
132
|
-
if (import.meta.client) {
|
|
133
|
-
let ws = null;
|
|
134
|
-
let reconnectTimeout = null;
|
|
135
|
-
let heartbeatInterval = null;
|
|
136
|
-
let heartbeatTimeout = null;
|
|
137
|
-
let awaitingPong = false;
|
|
138
|
-
let isConnecting = false;
|
|
139
|
-
let isMounted = false;
|
|
140
|
-
// Heartbeat configuration
|
|
141
|
-
const HEARTBEAT_INTERVAL = 25000; // 25 seconds (well under server's 90s timeout)
|
|
142
|
-
const HEARTBEAT_TIMEOUT = 15000; // 15 seconds to receive pong (generous for slow networks)
|
|
143
|
-
// Generate a unique subscription ID
|
|
144
|
-
const subscriptionId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
145
|
-
const startHeartbeat = () => {
|
|
146
|
-
stopHeartbeat();
|
|
147
|
-
heartbeatInterval = setInterval(() => {
|
|
148
|
-
if (ws?.readyState === WebSocket.OPEN) {
|
|
149
|
-
awaitingPong = true;
|
|
150
|
-
ws.send(JSON.stringify({ type: 'ping' }));
|
|
151
|
-
heartbeatTimeout = setTimeout(() => {
|
|
152
|
-
if (awaitingPong && isMounted) {
|
|
153
|
-
console.warn('[Tether] Heartbeat timeout - forcing reconnect');
|
|
154
|
-
ws?.close();
|
|
155
|
-
}
|
|
156
|
-
}, HEARTBEAT_TIMEOUT);
|
|
157
|
-
}
|
|
158
|
-
}, HEARTBEAT_INTERVAL);
|
|
159
|
-
};
|
|
160
|
-
const stopHeartbeat = () => {
|
|
161
|
-
if (heartbeatInterval) {
|
|
162
|
-
clearInterval(heartbeatInterval);
|
|
163
|
-
heartbeatInterval = null;
|
|
164
|
-
}
|
|
165
|
-
if (heartbeatTimeout) {
|
|
166
|
-
clearTimeout(heartbeatTimeout);
|
|
167
|
-
heartbeatTimeout = null;
|
|
168
|
-
}
|
|
169
|
-
awaitingPong = false;
|
|
170
|
-
};
|
|
171
|
-
const connect = () => {
|
|
172
|
-
// Don't connect if unmounted or already connecting/connected
|
|
173
|
-
if (!isMounted)
|
|
174
|
-
return;
|
|
175
|
-
if (isConnecting)
|
|
176
|
-
return;
|
|
177
|
-
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
// Get config from window (set by plugin)
|
|
181
|
-
const config = window.__TETHER_CONFIG__;
|
|
182
|
-
if (!config?.wsUrl || !config?.projectId) {
|
|
183
|
-
console.warn('[Tether] WebSocket config not available');
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
isConnecting = true;
|
|
187
|
-
const wsUrl = `${config.wsUrl}/ws/${config.projectId}`;
|
|
188
|
-
ws = new WebSocket(wsUrl);
|
|
189
|
-
ws.onopen = () => {
|
|
190
|
-
isConnecting = false;
|
|
191
|
-
// Wait for connected message before subscribing
|
|
192
|
-
};
|
|
193
|
-
ws.onmessage = (event) => {
|
|
194
|
-
try {
|
|
195
|
-
const message = JSON.parse(event.data);
|
|
196
|
-
if (message.type === 'connected') {
|
|
197
|
-
isConnected.value = true;
|
|
198
|
-
startHeartbeat();
|
|
199
|
-
// Subscribe to the query with our ID
|
|
200
|
-
ws?.send(JSON.stringify({
|
|
201
|
-
type: 'subscribe',
|
|
202
|
-
id: subscriptionId,
|
|
203
|
-
query: queryName,
|
|
204
|
-
args,
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
else if (message.type === 'data' && message.id === subscriptionId) {
|
|
208
|
-
// Call onUpdate with the fresh data
|
|
209
|
-
onUpdate(message.data);
|
|
210
|
-
}
|
|
211
|
-
else if (message.type === 'pong') {
|
|
212
|
-
// Heartbeat acknowledged
|
|
213
|
-
awaitingPong = false;
|
|
214
|
-
if (heartbeatTimeout) {
|
|
215
|
-
clearTimeout(heartbeatTimeout);
|
|
216
|
-
heartbeatTimeout = null;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
// Ignore parse errors
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
ws.onclose = () => {
|
|
225
|
-
isConnected.value = false;
|
|
226
|
-
isConnecting = false;
|
|
227
|
-
stopHeartbeat();
|
|
228
|
-
// Only reconnect if still mounted
|
|
229
|
-
if (isMounted) {
|
|
230
|
-
reconnectTimeout = setTimeout(connect, 3000);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
ws.onerror = () => {
|
|
234
|
-
isConnecting = false;
|
|
235
|
-
ws?.close();
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
// Handle page visibility changes - reconnect when tab becomes visible
|
|
239
|
-
const handleVisibilityChange = () => {
|
|
240
|
-
if (!isMounted)
|
|
241
|
-
return;
|
|
242
|
-
if (document.visibilityState === 'visible') {
|
|
243
|
-
// Tab became visible - check connection health
|
|
244
|
-
if (!ws || ws.readyState === WebSocket.CLOSED) {
|
|
245
|
-
// Clear any pending reconnect and connect immediately
|
|
246
|
-
if (reconnectTimeout) {
|
|
247
|
-
clearTimeout(reconnectTimeout);
|
|
248
|
-
reconnectTimeout = null;
|
|
249
|
-
}
|
|
250
|
-
connect();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
onMounted(() => {
|
|
255
|
-
isMounted = true;
|
|
256
|
-
connect();
|
|
257
|
-
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
258
|
-
});
|
|
259
|
-
onUnmounted(() => {
|
|
260
|
-
isMounted = false;
|
|
261
|
-
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
262
|
-
stopHeartbeat();
|
|
263
|
-
if (reconnectTimeout) {
|
|
264
|
-
clearTimeout(reconnectTimeout);
|
|
265
|
-
reconnectTimeout = null;
|
|
266
|
-
}
|
|
267
|
-
if (ws) {
|
|
268
|
-
ws.close();
|
|
269
|
-
ws = null;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return { isConnected };
|
|
274
|
-
}
|
|
275
|
-
//# sourceMappingURL=composables.js.map
|