@taujs/react 0.1.6 → 0.1.7
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 +1 -67
- package/dist/index.js +0 -63
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -88,70 +88,4 @@ declare function createRenderer<T extends Record<string, unknown> = Record<strin
|
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
* τjs Client Data Bridge
|
|
93
|
-
*
|
|
94
|
-
* Provides framework-agnostic primitives for accessing route data:
|
|
95
|
-
* - SSR hydration (window.__INITIAL_DATA__)
|
|
96
|
-
* - Client-side fetch (/__taujs/route endpoint)
|
|
97
|
-
*
|
|
98
|
-
* This is a transport layer only. For data orchestration (caching, refetch, etc.),
|
|
99
|
-
* use TanStack Query or similar.
|
|
100
|
-
*/
|
|
101
|
-
type RouteData = Record<string, unknown>;
|
|
102
|
-
/**
|
|
103
|
-
* Error thrown when fetchRouteData receives a non-2xx response.
|
|
104
|
-
* Contains structured error information from the server.
|
|
105
|
-
*/
|
|
106
|
-
declare class RouteDataError extends Error {
|
|
107
|
-
readonly status: number;
|
|
108
|
-
readonly statusText: string;
|
|
109
|
-
readonly code?: string;
|
|
110
|
-
readonly body?: unknown;
|
|
111
|
-
constructor(message: string, opts: {
|
|
112
|
-
status: number;
|
|
113
|
-
statusText: string;
|
|
114
|
-
code?: string;
|
|
115
|
-
body?: unknown;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Read SSR boot data from window.__INITIAL_DATA__ exactly once.
|
|
120
|
-
* Subsequent calls return null (forces client-side fetch).
|
|
121
|
-
*
|
|
122
|
-
* Returns null on server (typeof window === 'undefined').
|
|
123
|
-
*/
|
|
124
|
-
declare function readInitialDataOnce<T extends RouteData = RouteData>(): T | null;
|
|
125
|
-
/**
|
|
126
|
-
* Fetch route data from the τjs data endpoint.
|
|
127
|
-
*
|
|
128
|
-
* Calls: GET /__taujs/route?url=<pathname>
|
|
129
|
-
* Returns: { data: T }
|
|
130
|
-
*
|
|
131
|
-
* Throws RouteDataError on non-2xx responses with structured error info.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* const data = await fetchRouteData('/app/dashboard');
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* try {
|
|
138
|
-
* const data = await fetchRouteData('/app/dashboard');
|
|
139
|
-
* } catch (err) {
|
|
140
|
-
* if (err instanceof RouteDataError && err.status === 404) {
|
|
141
|
-
* // Handle not found
|
|
142
|
-
* }
|
|
143
|
-
* }
|
|
144
|
-
*/
|
|
145
|
-
declare function fetchRouteData<T extends RouteData = RouteData>(pathname: string, init?: RequestInit): Promise<T>;
|
|
146
|
-
/**
|
|
147
|
-
* Get the current browser path (pathname + search).
|
|
148
|
-
* Does not include hash.
|
|
149
|
-
*
|
|
150
|
-
* Returns null on server (typeof window === 'undefined').
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* const path = getCurrentPath(); // "/app/dashboard?tab=overview"
|
|
154
|
-
*/
|
|
155
|
-
declare function getCurrentPath(): string | null;
|
|
156
|
-
|
|
157
|
-
export { type HeadContext, type HydrateAppOptions, type RenderCallbacks, type RouteData, RouteDataError, type SSRStore, SSRStoreProvider, type ServerLogs, type StreamOptions, createRenderer, createSSRStore, fetchRouteData, getCurrentPath, hydrateApp, readInitialDataOnce, useSSRStore };
|
|
91
|
+
export { type HeadContext, type HydrateAppOptions, type RenderCallbacks, type SSRStore, SSRStoreProvider, type ServerLogs, type StreamOptions, createRenderer, createSSRStore, hydrateApp, useSSRStore };
|
package/dist/index.js
CHANGED
|
@@ -548,73 +548,10 @@ function createRenderer({
|
|
|
548
548
|
};
|
|
549
549
|
return { renderSSR, renderStream };
|
|
550
550
|
}
|
|
551
|
-
|
|
552
|
-
// src/RouteData.ts
|
|
553
|
-
var RouteDataError = class _RouteDataError extends Error {
|
|
554
|
-
status;
|
|
555
|
-
statusText;
|
|
556
|
-
code;
|
|
557
|
-
body;
|
|
558
|
-
constructor(message, opts) {
|
|
559
|
-
super(message);
|
|
560
|
-
this.name = "RouteDataError";
|
|
561
|
-
this.status = opts.status;
|
|
562
|
-
this.statusText = opts.statusText;
|
|
563
|
-
this.code = opts.code;
|
|
564
|
-
this.body = opts.body;
|
|
565
|
-
Object.setPrototypeOf(this, _RouteDataError.prototype);
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
var INITIAL_DATA_KEY = "__INITIAL_DATA__";
|
|
569
|
-
function readInitialDataOnce() {
|
|
570
|
-
if (typeof window === "undefined") return null;
|
|
571
|
-
const w = window;
|
|
572
|
-
const data = w[INITIAL_DATA_KEY];
|
|
573
|
-
if (!data) return null;
|
|
574
|
-
delete w[INITIAL_DATA_KEY];
|
|
575
|
-
return data;
|
|
576
|
-
}
|
|
577
|
-
async function fetchRouteData(pathname, init) {
|
|
578
|
-
if (!pathname) {
|
|
579
|
-
throw new Error("fetchRouteData: pathname is required");
|
|
580
|
-
}
|
|
581
|
-
const url = `/__taujs/route?url=${encodeURIComponent(pathname)}`;
|
|
582
|
-
const res = await fetch(url, {
|
|
583
|
-
credentials: "include",
|
|
584
|
-
...init
|
|
585
|
-
});
|
|
586
|
-
if (!res.ok) {
|
|
587
|
-
let body2;
|
|
588
|
-
try {
|
|
589
|
-
body2 = await res.json();
|
|
590
|
-
} catch {
|
|
591
|
-
const text = await res.text().catch(() => "");
|
|
592
|
-
body2 = { error: text };
|
|
593
|
-
}
|
|
594
|
-
const json = body2;
|
|
595
|
-
throw new RouteDataError(json.error ?? `Request failed: ${res.status}`, {
|
|
596
|
-
status: res.status,
|
|
597
|
-
statusText: json.statusText ?? res.statusText,
|
|
598
|
-
code: json.code,
|
|
599
|
-
body: body2
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
const body = await res.json();
|
|
603
|
-
return body.data ?? {};
|
|
604
|
-
}
|
|
605
|
-
function getCurrentPath() {
|
|
606
|
-
if (typeof window === "undefined") return null;
|
|
607
|
-
const { pathname, search } = window.location;
|
|
608
|
-
return `${pathname}${search}`;
|
|
609
|
-
}
|
|
610
551
|
export {
|
|
611
|
-
RouteDataError,
|
|
612
552
|
SSRStoreProvider,
|
|
613
553
|
createRenderer,
|
|
614
554
|
createSSRStore,
|
|
615
|
-
fetchRouteData,
|
|
616
|
-
getCurrentPath,
|
|
617
555
|
hydrateApp,
|
|
618
|
-
readInitialDataOnce,
|
|
619
556
|
useSSRStore
|
|
620
557
|
};
|