@rivi-software/radiotools-sdk-vue 0.2.0
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/package.json +35 -0
- package/src/composables.generated.ts +66 -0
- package/src/index.ts +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rivi-software/radiotools-sdk-vue",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vue composables for @rivi-software/radiotools-sdk (generated from @rivi-software/radiotools-contract)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"scripts": {
|
|
15
|
+
"check": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@rivi-software/radiotools-sdk": "workspace:*"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"vue": ">=3.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "5.9.3",
|
|
25
|
+
"vue": "3.5.22"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/RIVI-Software/radiotools-sdk.git",
|
|
33
|
+
"directory": "packages/sdk-vue"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Generated by @rivi-software/radiotools-sdk-generator — do not edit by hand. */
|
|
2
|
+
import { type Ref, onMounted, onUnmounted, ref, shallowRef } from "vue";
|
|
3
|
+
import type { StationClient } from "@rivi-software/radiotools-sdk";
|
|
4
|
+
|
|
5
|
+
export type StationQuery<T> = {
|
|
6
|
+
data: Ref<T | undefined>;
|
|
7
|
+
error: Ref<Error | undefined>;
|
|
8
|
+
loading: Ref<boolean>;
|
|
9
|
+
refresh: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function useStationQuery<T>(read: () => Promise<T>): StationQuery<T> {
|
|
13
|
+
const data = shallowRef<T | undefined>(undefined);
|
|
14
|
+
const error = ref<Error | undefined>(undefined);
|
|
15
|
+
const loading = ref(true);
|
|
16
|
+
let active = true;
|
|
17
|
+
|
|
18
|
+
const refresh = async () => {
|
|
19
|
+
loading.value = true;
|
|
20
|
+
try {
|
|
21
|
+
const value = await read();
|
|
22
|
+
if (!active) return;
|
|
23
|
+
data.value = value;
|
|
24
|
+
error.value = undefined;
|
|
25
|
+
} catch (cause: unknown) {
|
|
26
|
+
if (!active) return;
|
|
27
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
28
|
+
} finally {
|
|
29
|
+
if (active) loading.value = false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
active = true;
|
|
35
|
+
void refresh();
|
|
36
|
+
});
|
|
37
|
+
onUnmounted(() => {
|
|
38
|
+
active = false;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return { data, error, loading, refresh };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useRecommendedPollInterval(client: StationClient): StationQuery<number> {
|
|
45
|
+
return useStationQuery(() => client.recommendedPollIntervalMs());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function useGetStation(client: StationClient) {
|
|
49
|
+
return useStationQuery(() => client.getStation());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function useGetCurrentBroadcast(client: StationClient) {
|
|
53
|
+
return useStationQuery(() => client.getCurrentBroadcast());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function useGetNowPlaying(client: StationClient) {
|
|
57
|
+
return useStationQuery(() => client.getNowPlaying());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useGetWeather(client: StationClient) {
|
|
61
|
+
return useStationQuery(() => client.getWeather());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useGetTraffic(client: StationClient) {
|
|
65
|
+
return useStationQuery(() => client.getTraffic());
|
|
66
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./composables.generated";
|