@go-avro/avro-js 0.0.2-beta.134 → 0.0.2-beta.135
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/auth/storage.js +5 -2
- package/dist/client/AvroQueryClientProvider.d.ts +14 -0
- package/dist/client/AvroQueryClientProvider.js +32 -0
- package/dist/client/QueryClient.d.ts +0 -1
- package/dist/client/QueryClient.js +2 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/auth/storage.js
CHANGED
|
@@ -17,8 +17,11 @@ export class LocalStorage {
|
|
|
17
17
|
this.key = 'cache_data';
|
|
18
18
|
}
|
|
19
19
|
async get(key) {
|
|
20
|
-
const item = localStorage.getItem(this.key);
|
|
21
|
-
|
|
20
|
+
const item = JSON.parse(localStorage.getItem(this.key) ?? 'null');
|
|
21
|
+
if (typeof item !== 'object' || item === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return item ? key ? item[key] ?? null : item : null;
|
|
22
25
|
}
|
|
23
26
|
async set(data) {
|
|
24
27
|
const current = await this.get() || {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { AvroQueryClient, AvroQueryClientConfig } from "./QueryClient";
|
|
4
|
+
import { AuthManager } from "../auth/AuthManager";
|
|
5
|
+
export interface AvroQueryClientProviderProps {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
authManager: AuthManager;
|
|
8
|
+
queryClient?: QueryClient;
|
|
9
|
+
configOverrides?: Partial<AvroQueryClientConfig>;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const AvroQueryClientProvider: ({ baseUrl, authManager, configOverrides, children, }: AvroQueryClientProviderProps) => React.JSX.Element;
|
|
13
|
+
export declare const useAvroQueryClient: () => AvroQueryClient;
|
|
14
|
+
export default AvroQueryClientProvider;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo, useEffect } from "react";
|
|
2
|
+
import { AvroQueryClient } from "./QueryClient";
|
|
3
|
+
const AvroQueryClientContext = createContext(null);
|
|
4
|
+
export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides, children, }) => {
|
|
5
|
+
const client = useMemo(() => {
|
|
6
|
+
const cfg = {
|
|
7
|
+
baseUrl,
|
|
8
|
+
authManager,
|
|
9
|
+
...(configOverrides || {}),
|
|
10
|
+
};
|
|
11
|
+
return new AvroQueryClient(cfg);
|
|
12
|
+
}, [baseUrl, authManager, configOverrides]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
return () => {
|
|
15
|
+
try {
|
|
16
|
+
client.socket?.disconnect();
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}, [client]);
|
|
23
|
+
return (React.createElement(AvroQueryClientContext.Provider, { value: client }, children));
|
|
24
|
+
};
|
|
25
|
+
export const useAvroQueryClient = () => {
|
|
26
|
+
const ctx = useContext(AvroQueryClientContext);
|
|
27
|
+
if (!ctx) {
|
|
28
|
+
throw new Error("useAvroQueryClient must be used within <AvroQueryClientProvider>");
|
|
29
|
+
}
|
|
30
|
+
return ctx;
|
|
31
|
+
};
|
|
32
|
+
export default AvroQueryClientProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import io from 'socket.io-client';
|
|
2
|
-
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { LoginResponse } from '../types/api';
|
|
4
4
|
import { StandardError } from '../types/error';
|
|
5
5
|
export class AvroQueryClient {
|
|
@@ -12,7 +12,6 @@ export class AvroQueryClient {
|
|
|
12
12
|
this.config = {
|
|
13
13
|
baseUrl: config.baseUrl,
|
|
14
14
|
authManager: config.authManager,
|
|
15
|
-
queryClient: config.queryClient,
|
|
16
15
|
maxRetries: config.maxRetries ?? 3,
|
|
17
16
|
retryStrategy: config.retryStrategy ?? 'fixed',
|
|
18
17
|
timeout: config.timeout ?? 0,
|
|
@@ -233,7 +232,7 @@ export class AvroQueryClient {
|
|
|
233
232
|
return this.config.authManager.isAuthenticated();
|
|
234
233
|
}
|
|
235
234
|
getQueryClient() {
|
|
236
|
-
return
|
|
235
|
+
return useQueryClient();
|
|
237
236
|
}
|
|
238
237
|
useLogout() {
|
|
239
238
|
const queryClient = this.getQueryClient();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClientConfig, AvroQueryClient } from './client/QueryClient';
|
|
2
|
+
export { AvroQueryClientProvider } from './client/AvroQueryClientProvider';
|
|
2
3
|
export { AuthManager } from './auth/AuthManager';
|
|
3
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
4
5
|
import './client/core/xhr';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClient } from './client/QueryClient';
|
|
2
|
+
export { AvroQueryClientProvider } from './client/AvroQueryClientProvider';
|
|
2
3
|
export { AuthManager } from './auth/AuthManager';
|
|
3
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
4
5
|
import './client/core/xhr';
|