@rivi-software/radiotools-sdk-next 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 ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@rivi-software/radiotools-sdk-next",
3
+ "version": "0.2.0",
4
+ "description": "Next.js App Router server helpers for @rivi-software/radiotools-sdk (generated)",
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
+ "server-only": "0.0.1"
20
+ },
21
+ "peerDependencies": {
22
+ "next": ">=14.2"
23
+ },
24
+ "devDependencies": {
25
+ "next": "15.5.4",
26
+ "typescript": "5.9.3"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/RIVI-Software/radiotools-sdk.git",
34
+ "directory": "packages/sdk-next"
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./server.generated";
@@ -0,0 +1,93 @@
1
+ /** Generated by @rivi-software/radiotools-sdk-generator — do not edit by hand. */
2
+ import "server-only";
3
+
4
+ import {
5
+ createStationClientFromEnv,
6
+ type CreateStationClientOptions,
7
+ type StationClient,
8
+ } from "@rivi-software/radiotools-sdk";
9
+ import { unstable_cache } from "next/cache";
10
+ import { NextResponse } from "next/server";
11
+
12
+ const DEFAULT_REVALIDATE_SECONDS = 30;
13
+
14
+ export function createRadioToolsServerClient(
15
+ overrides: Partial<CreateStationClientOptions> = {},
16
+ ): StationClient {
17
+ return createStationClientFromEnv(undefined, overrides);
18
+ }
19
+
20
+ export function createCachedRadioToolsReader<T>(
21
+ cacheKey: string,
22
+ read: (client: StationClient) => Promise<T>,
23
+ revalidateSeconds: number = DEFAULT_REVALIDATE_SECONDS,
24
+ ) {
25
+ return unstable_cache(async () => read(createRadioToolsServerClient()), [cacheKey], {
26
+ revalidate: revalidateSeconds,
27
+ });
28
+ }
29
+
30
+ export async function fetchGetStation(client: StationClient) {
31
+ return client.getStation();
32
+ }
33
+
34
+ export async function fetchGetCurrentBroadcast(client: StationClient) {
35
+ return client.getCurrentBroadcast();
36
+ }
37
+
38
+ export async function fetchGetNowPlaying(client: StationClient) {
39
+ return client.getNowPlaying();
40
+ }
41
+
42
+ export async function fetchGetWeather(client: StationClient) {
43
+ return client.getWeather();
44
+ }
45
+
46
+ export async function fetchGetTraffic(client: StationClient) {
47
+ return client.getTraffic();
48
+ }
49
+
50
+ export async function fetchRecommendedPollIntervalMs(client: StationClient) {
51
+ return client.recommendedPollIntervalMs();
52
+ }
53
+
54
+ export const cachedGetStation = createCachedRadioToolsReader("radiotools:station", (c) => c.getStation());
55
+ export const cachedGetNowPlaying = createCachedRadioToolsReader("radiotools:now-playing", (c) =>
56
+ c.getNowPlaying(),
57
+ );
58
+ export const cachedGetCurrentBroadcast = createCachedRadioToolsReader(
59
+ "radiotools:current-broadcast",
60
+ (c) => c.getCurrentBroadcast(),
61
+ );
62
+
63
+ /** App Router helper for `/api/radiotools/-station` */
64
+ export async function jsonResponseStation(client: StationClient) {
65
+ const data = await client.getStation();
66
+ return NextResponse.json(data);
67
+ }
68
+
69
+ /** App Router helper for `/api/radiotools/-current-broadcast` */
70
+ export async function jsonResponseCurrentBroadcast(client: StationClient) {
71
+ const data = await client.getCurrentBroadcast();
72
+ return NextResponse.json(data);
73
+ }
74
+
75
+ /** App Router helper for `/api/radiotools/-now-playing` */
76
+ export async function jsonResponseNowPlaying(client: StationClient) {
77
+ const data = await client.getNowPlaying();
78
+ return NextResponse.json(data);
79
+ }
80
+
81
+ /** App Router helper for `/api/radiotools/-weather` */
82
+ export async function jsonResponseWeather(client: StationClient) {
83
+ const data = await client.getWeather();
84
+ return NextResponse.json(data);
85
+ }
86
+
87
+ /** App Router helper for `/api/radiotools/-traffic` */
88
+ export async function jsonResponseTraffic(client: StationClient) {
89
+ const data = await client.getTraffic();
90
+ return NextResponse.json(data);
91
+ }
92
+
93
+ export type { StationClient, CreateStationClientOptions };