@tthr/vue 0.0.1
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/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tthr/vue - Tether Vue/Nuxt SDK
|
|
3
|
+
*
|
|
4
|
+
* Reactive data fetching and mutations for Vue and Nuxt applications.
|
|
5
|
+
*/
|
|
6
|
+
import { type Ref, type App } from 'vue';
|
|
7
|
+
import { TetherClient, type TetherClientOptions } from '@tthr/client';
|
|
8
|
+
/**
|
|
9
|
+
* Tether plugin for Vue/Nuxt
|
|
10
|
+
*/
|
|
11
|
+
export declare const TetherPlugin: {
|
|
12
|
+
install(app: App, options: TetherClientOptions): void;
|
|
13
|
+
configure(options: TetherClientOptions): void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Get the Tether client instance
|
|
17
|
+
*/
|
|
18
|
+
export declare function useTether(): TetherClient;
|
|
19
|
+
/**
|
|
20
|
+
* Query state returned by useQuery
|
|
21
|
+
*/
|
|
22
|
+
export interface QueryState<T> {
|
|
23
|
+
data: Ref<T | undefined>;
|
|
24
|
+
error: Ref<Error | null>;
|
|
25
|
+
isLoading: Ref<boolean>;
|
|
26
|
+
refetch: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Query function reference
|
|
30
|
+
*/
|
|
31
|
+
export interface QueryFunction<TArgs = void, TResult = unknown> {
|
|
32
|
+
_name: string;
|
|
33
|
+
_args?: TArgs;
|
|
34
|
+
_result?: TResult;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Reactive query composable
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```vue
|
|
41
|
+
* <script setup>
|
|
42
|
+
* import { useQuery } from '@tthr/vue';
|
|
43
|
+
* import { api } from '../_generated/api';
|
|
44
|
+
*
|
|
45
|
+
* const posts = useQuery(api.posts.list);
|
|
46
|
+
* </script>
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function useQuery<TArgs, TResult>(query: QueryFunction<TArgs, TResult>, args?: TArgs): QueryState<TResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Mutation state returned by useMutation
|
|
52
|
+
*/
|
|
53
|
+
export interface MutationState<TArgs, TResult> {
|
|
54
|
+
data: Ref<TResult | undefined>;
|
|
55
|
+
error: Ref<Error | null>;
|
|
56
|
+
isPending: Ref<boolean>;
|
|
57
|
+
mutate: (args: TArgs) => Promise<TResult>;
|
|
58
|
+
reset: () => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Mutation function reference
|
|
62
|
+
*/
|
|
63
|
+
export interface MutationFunction<TArgs = void, TResult = unknown> {
|
|
64
|
+
_name: string;
|
|
65
|
+
_args?: TArgs;
|
|
66
|
+
_result?: TResult;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Mutation composable
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```vue
|
|
73
|
+
* <script setup>
|
|
74
|
+
* import { useMutation } from '@tthr/vue';
|
|
75
|
+
* import { api } from '../_generated/api';
|
|
76
|
+
*
|
|
77
|
+
* const createPost = useMutation(api.posts.create);
|
|
78
|
+
* await createPost.mutate({ title: 'Hello', content: '...' });
|
|
79
|
+
* </script>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function useMutation<TArgs, TResult>(mutation: MutationFunction<TArgs, TResult>): MutationState<TArgs, TResult>;
|
|
83
|
+
export type { TetherClientOptions } from '@tthr/client';
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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AAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,IAAI,EAAE,OAAO,GAAG,OAAO;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EACxC,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,GACzC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAmC/B;AAGD,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tthr/vue - Tether Vue/Nuxt SDK
|
|
3
|
+
*
|
|
4
|
+
* Reactive data fetching and mutations for Vue and Nuxt applications.
|
|
5
|
+
*/
|
|
6
|
+
import { ref, onMounted, onUnmounted } from 'vue';
|
|
7
|
+
import { TetherClient } from '@tthr/client';
|
|
8
|
+
// Global client instance
|
|
9
|
+
let globalClient = null;
|
|
10
|
+
/**
|
|
11
|
+
* Tether plugin for Vue/Nuxt
|
|
12
|
+
*/
|
|
13
|
+
export const TetherPlugin = {
|
|
14
|
+
install(app, options) {
|
|
15
|
+
globalClient = new TetherClient(options);
|
|
16
|
+
app.provide('tether', globalClient);
|
|
17
|
+
},
|
|
18
|
+
configure(options) {
|
|
19
|
+
globalClient = new TetherClient(options);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get the Tether client instance
|
|
24
|
+
*/
|
|
25
|
+
export function useTether() {
|
|
26
|
+
if (!globalClient) {
|
|
27
|
+
throw new Error('Tether client not initialised. Call TetherPlugin.configure() first.');
|
|
28
|
+
}
|
|
29
|
+
return globalClient;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reactive query composable
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```vue
|
|
36
|
+
* <script setup>
|
|
37
|
+
* import { useQuery } from '@tthr/vue';
|
|
38
|
+
* import { api } from '../_generated/api';
|
|
39
|
+
*
|
|
40
|
+
* const posts = useQuery(api.posts.list);
|
|
41
|
+
* </script>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useQuery(query, args) {
|
|
45
|
+
const data = ref();
|
|
46
|
+
const error = ref(null);
|
|
47
|
+
const isLoading = ref(true);
|
|
48
|
+
let unsubscribe = null;
|
|
49
|
+
const fetchData = async () => {
|
|
50
|
+
try {
|
|
51
|
+
isLoading.value = true;
|
|
52
|
+
error.value = null;
|
|
53
|
+
const client = useTether();
|
|
54
|
+
const result = await client.query(query._name, args);
|
|
55
|
+
data.value = result;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
error.value = e instanceof Error ? e : new Error(String(e));
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
isLoading.value = false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
onMounted(async () => {
|
|
65
|
+
await fetchData();
|
|
66
|
+
// Subscribe to updates
|
|
67
|
+
const client = useTether();
|
|
68
|
+
unsubscribe = client.subscribe(query._name, args, (newData) => {
|
|
69
|
+
data.value = newData;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
onUnmounted(() => {
|
|
73
|
+
if (unsubscribe) {
|
|
74
|
+
unsubscribe();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
data: data,
|
|
79
|
+
error,
|
|
80
|
+
isLoading,
|
|
81
|
+
refetch: fetchData,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Mutation composable
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```vue
|
|
89
|
+
* <script setup>
|
|
90
|
+
* import { useMutation } from '@tthr/vue';
|
|
91
|
+
* import { api } from '../_generated/api';
|
|
92
|
+
*
|
|
93
|
+
* const createPost = useMutation(api.posts.create);
|
|
94
|
+
* await createPost.mutate({ title: 'Hello', content: '...' });
|
|
95
|
+
* </script>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function useMutation(mutation) {
|
|
99
|
+
const data = ref();
|
|
100
|
+
const error = ref(null);
|
|
101
|
+
const isPending = ref(false);
|
|
102
|
+
const mutate = async (args) => {
|
|
103
|
+
try {
|
|
104
|
+
isPending.value = true;
|
|
105
|
+
error.value = null;
|
|
106
|
+
const client = useTether();
|
|
107
|
+
const result = await client.mutation(mutation._name, args);
|
|
108
|
+
data.value = result;
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
error.value = e instanceof Error ? e : new Error(String(e));
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
isPending.value = false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const reset = () => {
|
|
120
|
+
data.value = undefined;
|
|
121
|
+
error.value = null;
|
|
122
|
+
isPending.value = false;
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
data: data,
|
|
126
|
+
error,
|
|
127
|
+
isPending,
|
|
128
|
+
mutate,
|
|
129
|
+
reset,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAsB,MAAM,KAAK,CAAC;AACtE,OAAO,EAAE,YAAY,EAA4B,MAAM,cAAc,CAAC;AAEtE,yBAAyB;AACzB,IAAI,YAAY,GAAwB,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,GAAG,MAAiB,CAAC;YAC/B,OAAO,MAAiB,CAAC;QAC3B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,MAAM,CAAC,CAAC;QACV,CAAC;gBAAS,CAAC;YACT,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACnB,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,IAAgC;QACtC,KAAK;QACL,SAAS;QACT,MAAM;QACN,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tthr/vue",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Tether Vue/Nuxt SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"typecheck": "tsc --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@tthr/client": "*"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.7.2"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": "^3.5.0"
|
|
30
|
+
}
|
|
31
|
+
}
|