@archbase/ssr 3.0.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/README.md +411 -0
- package/dist/archbase-ssr-3.0.0.tgz +0 -0
- package/dist/datasource/ArchbaseSSRDataSource.d.ts +122 -0
- package/dist/hooks/useArchbaseSSRDataSource.d.ts +94 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +655 -0
- package/dist/providers/ArchbaseSSRProvider.d.ts +52 -0
- package/dist/tanstack/ArchbaseTanStackIntegration.d.ts +67 -0
- package/dist/utils/ArchbaseSSRUtils.d.ts +81 -0
- package/package.json +57 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
interface ArchbaseTanStackProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** Custom QueryClient instance */
|
|
6
|
+
queryClient?: QueryClient;
|
|
7
|
+
/** Server-side dehydrated state */
|
|
8
|
+
dehydratedState?: any;
|
|
9
|
+
/** Default stale time for queries */
|
|
10
|
+
defaultStaleTime?: number;
|
|
11
|
+
/** Default cache time for queries */
|
|
12
|
+
defaultCacheTime?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* TanStack Query provider with SSR support for Archbase
|
|
16
|
+
*/
|
|
17
|
+
export declare function ArchbaseTanStackProvider({ children, queryClient: providedQueryClient, dehydratedState, defaultStaleTime, // 5 minutes
|
|
18
|
+
defaultCacheTime, }: ArchbaseTanStackProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Hook to create TanStack queries that work with Archbase DataSources
|
|
21
|
+
*/
|
|
22
|
+
export declare function useArchbaseQuery<TData = unknown, TError = Error>(key: string | readonly unknown[], fetchFn: () => Promise<TData>, options?: {
|
|
23
|
+
/** Archbase DataSource to sync with */
|
|
24
|
+
dataSource?: any;
|
|
25
|
+
/** Auto-update DataSource when query succeeds */
|
|
26
|
+
syncWithDataSource?: boolean;
|
|
27
|
+
/** Transform data before setting to DataSource */
|
|
28
|
+
transformForDataSource?: (data: TData) => any[];
|
|
29
|
+
/** SSR initial data */
|
|
30
|
+
ssrData?: TData;
|
|
31
|
+
/** Enable SSR for this query */
|
|
32
|
+
ssr?: boolean;
|
|
33
|
+
} & Omit<any, 'queryKey' | 'queryFn'>): {
|
|
34
|
+
data: any;
|
|
35
|
+
isLoading: boolean;
|
|
36
|
+
error: TError | null;
|
|
37
|
+
isSuccess: boolean;
|
|
38
|
+
isError: boolean;
|
|
39
|
+
refetch: () => Promise<{
|
|
40
|
+
data: Awaited<TData>;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Utility to serialize QueryClient state for SSR
|
|
45
|
+
*/
|
|
46
|
+
export declare function serializeQueryClientState(queryClient: QueryClient): string;
|
|
47
|
+
/**
|
|
48
|
+
* Server-side utility to prepare query data
|
|
49
|
+
*/
|
|
50
|
+
export declare function prepareServerQueries(queryClient: QueryClient, queries: Array<{
|
|
51
|
+
key: string | readonly unknown[];
|
|
52
|
+
fetchFn: () => Promise<unknown>;
|
|
53
|
+
}>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Higher-order component to provide TanStack Start integration
|
|
56
|
+
*/
|
|
57
|
+
export declare function withArchbaseTanStack<P extends object>(Component: React.ComponentType<P>, options?: {
|
|
58
|
+
queryClient?: QueryClient;
|
|
59
|
+
prefetchQueries?: (props: P) => Array<{
|
|
60
|
+
key: string | readonly unknown[];
|
|
61
|
+
fetchFn: () => Promise<unknown>;
|
|
62
|
+
}>;
|
|
63
|
+
}): {
|
|
64
|
+
(props: P): import("react/jsx-runtime").JSX.Element;
|
|
65
|
+
displayName: string;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for Server-Side Rendering with Archbase React
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if code is running on server side
|
|
6
|
+
*/
|
|
7
|
+
export declare const isServer: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if code is running on client side
|
|
10
|
+
*/
|
|
11
|
+
export declare const isClient: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Safe check for browser APIs
|
|
14
|
+
*/
|
|
15
|
+
export declare const canUseDOM: () => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Safely access localStorage with SSR compatibility
|
|
18
|
+
*/
|
|
19
|
+
export declare const safeLocalStorage: {
|
|
20
|
+
getItem(key: string): string | null;
|
|
21
|
+
setItem(key: string, value: string): void;
|
|
22
|
+
removeItem(key: string): void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Safely access sessionStorage with SSR compatibility
|
|
26
|
+
*/
|
|
27
|
+
export declare const safeSessionStorage: {
|
|
28
|
+
getItem(key: string): string | null;
|
|
29
|
+
setItem(key: string, value: string): void;
|
|
30
|
+
removeItem(key: string): void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Serialize data for SSR with circular reference handling
|
|
34
|
+
*/
|
|
35
|
+
export declare function serializeForSSR<T>(data: T): string;
|
|
36
|
+
/**
|
|
37
|
+
* Deserialize SSR data safely
|
|
38
|
+
*/
|
|
39
|
+
export declare function deserializeFromSSR<T>(serializedData: string): T | null;
|
|
40
|
+
export declare function createSSRId(prefix?: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Reset ID counter (useful for testing)
|
|
43
|
+
*/
|
|
44
|
+
export declare function resetSSRIdCounter(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Safely get window object
|
|
47
|
+
*/
|
|
48
|
+
export declare function getWindow(): Window | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Safely get document object
|
|
51
|
+
*/
|
|
52
|
+
export declare function getDocument(): Document | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a feature is available in the current environment
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasFeature(feature: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Wrap a value that might not be available during SSR
|
|
59
|
+
*/
|
|
60
|
+
export declare function withSSRFallback<T>(getValue: () => T, fallback: T): T;
|
|
61
|
+
/**
|
|
62
|
+
* Execute a function only on the client side
|
|
63
|
+
*/
|
|
64
|
+
export declare function clientOnly<T>(fn: () => T): T | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a function only on the server side
|
|
67
|
+
*/
|
|
68
|
+
export declare function serverOnly<T>(fn: () => T): T | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Create a value that's different between server and client
|
|
71
|
+
* Useful for hydration-safe random values
|
|
72
|
+
*/
|
|
73
|
+
export declare function createHydrationSafeValue<T>(serverValue: T, clientValue: () => T): T;
|
|
74
|
+
/**
|
|
75
|
+
* Media query hook that works with SSR
|
|
76
|
+
*/
|
|
77
|
+
export interface MediaQueryResult {
|
|
78
|
+
matches: boolean;
|
|
79
|
+
media: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function getMediaQuery(query: string): MediaQueryResult;
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@archbase/ssr",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Server-Side Rendering utilities for Archbase React components with TanStack Start",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": ">=18.0.0",
|
|
20
|
+
"react-dom": ">=18.0.0",
|
|
21
|
+
"@mantine/core": "8.3.12",
|
|
22
|
+
"@mantine/hooks": "8.3.12",
|
|
23
|
+
"@tanstack/react-query": "^5.0.0",
|
|
24
|
+
"@tanstack/start": "^1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"serialize-javascript": "^6.0.2",
|
|
28
|
+
"@archbase/core": "3.0.0",
|
|
29
|
+
"@archbase/data": "3.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/serialize-javascript": "^5.0.4",
|
|
33
|
+
"typescript": "^5.7.2",
|
|
34
|
+
"vite": "^6.0.1",
|
|
35
|
+
"vite-plugin-dts": "^4.3.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"react",
|
|
39
|
+
"ssr",
|
|
40
|
+
"server-side-rendering",
|
|
41
|
+
"tanstack-start",
|
|
42
|
+
"archbase",
|
|
43
|
+
"components"
|
|
44
|
+
],
|
|
45
|
+
"author": "Edson Martins",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/edsonmartins/archbase-react"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"dev": "vite build --watch",
|
|
54
|
+
"clean": "rm -rf dist",
|
|
55
|
+
"type-check": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|