@neevjs/client 0.0.1
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 +48 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +699 -0
- package/dist/index.mjs +656 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Rahul7raj/neevjs/main/docs/logo-inline.png" alt="NeevJS" height="80" />
|
|
3
|
+
<br />
|
|
4
|
+
<br />
|
|
5
|
+
<a href="https://github.com/Rahul7raj/neevjs"><strong>GitHub Repository</strong></a> | <a href="https://Rahul7raj.github.io/neevjs"><strong>Documentation</strong></a>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
# @neevjs/client
|
|
11
|
+
|
|
12
|
+
> NeevJS core React framework — plugin-driven, offline-first, built for business apps.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @neevjs/client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { createClient, NeevProvider, useModel, AuthPlugin } from '@neevjs/client'
|
|
24
|
+
|
|
25
|
+
const client = createClient({ baseURL: '/api' })
|
|
26
|
+
client.use(AuthPlugin)
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<NeevProvider client={client}>
|
|
31
|
+
<YourApp />
|
|
32
|
+
</NeevProvider>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function YourApp() {
|
|
37
|
+
const { data, loading, create, remove } = useModel('users')
|
|
38
|
+
// data, CRUD — all in one hook
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Docs
|
|
43
|
+
|
|
44
|
+
Full documentation at [Rahul7raj.github.io/neevjs](https://Rahul7raj.github.io/neevjs)
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT — Rahul Raj Kushwaha
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NeevClientConfig, NeevClientInterface, AuthInterface, AuthUser, ModelRecord, UseModelReturn, SyncStatus, NeevPlugin } from '@neevjs/shared';
|
|
2
|
+
export { ApiMeta, ApiResponse, AuthInterface, AuthLoginResponse, AuthUser, ModelRecord, NeevClientConfig, NeevClientInterface, NeevPlugin, NeevRequest, Pagination, QueuedAction, RequestOptions, SyncStatus, UseModelReturn } from '@neevjs/shared';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
declare function createClient(config?: NeevClientConfig): NeevClientInterface;
|
|
6
|
+
|
|
7
|
+
declare const NeevContext: React.Context<NeevClientInterface | null>;
|
|
8
|
+
interface NeevProviderProps {
|
|
9
|
+
client: NeevClientInterface;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare function NeevProvider({ client, children }: NeevProviderProps): React.ReactElement;
|
|
13
|
+
declare function useNeevClient(): NeevClientInterface;
|
|
14
|
+
|
|
15
|
+
declare class AuthClient implements AuthInterface {
|
|
16
|
+
private client;
|
|
17
|
+
private userData;
|
|
18
|
+
constructor(client: NeevClientInterface);
|
|
19
|
+
login(email: string, password: string): Promise<void>;
|
|
20
|
+
register(email: string, password: string, name?: string): Promise<void>;
|
|
21
|
+
logout(): void;
|
|
22
|
+
user(): Promise<AuthUser | null>;
|
|
23
|
+
isAuthenticated(): boolean;
|
|
24
|
+
getToken(): string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare function useModel<T extends ModelRecord>(name: string): UseModelReturn<T>;
|
|
28
|
+
|
|
29
|
+
declare function useAuth(): AuthInterface;
|
|
30
|
+
|
|
31
|
+
declare function useSyncStatus(): SyncStatus;
|
|
32
|
+
|
|
33
|
+
interface TableColumn<T extends ModelRecord> {
|
|
34
|
+
key: keyof T & string;
|
|
35
|
+
label?: string;
|
|
36
|
+
render?: (value: T[keyof T], row: T) => React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
interface TableProps<T extends ModelRecord> {
|
|
39
|
+
model: string;
|
|
40
|
+
columns?: TableColumn<T>[];
|
|
41
|
+
onEdit?: (row: T) => void;
|
|
42
|
+
onDelete?: (row: T) => void;
|
|
43
|
+
emptyMessage?: string;
|
|
44
|
+
}
|
|
45
|
+
declare function Table<T extends ModelRecord>({ model, columns, onEdit, onDelete, emptyMessage, }: TableProps<T>): React.ReactElement;
|
|
46
|
+
|
|
47
|
+
interface FormField {
|
|
48
|
+
name: string;
|
|
49
|
+
label?: string;
|
|
50
|
+
type?: 'text' | 'email' | 'password' | 'number' | 'textarea' | 'select';
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
required?: boolean;
|
|
53
|
+
options?: {
|
|
54
|
+
label: string;
|
|
55
|
+
value: string;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
interface FormProps<T extends ModelRecord> {
|
|
59
|
+
model: string;
|
|
60
|
+
fields?: FormField[];
|
|
61
|
+
initialValues?: Partial<T>;
|
|
62
|
+
editId?: number | string;
|
|
63
|
+
onSuccess?: () => void;
|
|
64
|
+
onError?: (err: Error) => void;
|
|
65
|
+
submitLabel?: string;
|
|
66
|
+
children?: React.ReactNode;
|
|
67
|
+
}
|
|
68
|
+
declare function Form<T extends ModelRecord>({ model, fields, initialValues, editId, onSuccess, onError, submitLabel, children, }: FormProps<T>): React.ReactElement;
|
|
69
|
+
|
|
70
|
+
interface ProtectedProps {
|
|
71
|
+
children: React.ReactNode;
|
|
72
|
+
fallback?: React.ReactNode;
|
|
73
|
+
role?: string;
|
|
74
|
+
}
|
|
75
|
+
declare function Protected({ children, fallback, role }: ProtectedProps): React.ReactElement;
|
|
76
|
+
|
|
77
|
+
declare const AuthPlugin: NeevPlugin;
|
|
78
|
+
|
|
79
|
+
declare const LoggerPlugin: NeevPlugin;
|
|
80
|
+
|
|
81
|
+
interface CachePluginOptions {
|
|
82
|
+
/** TTL in milliseconds. Default: 60_000 (1 minute) */
|
|
83
|
+
ttl?: number;
|
|
84
|
+
}
|
|
85
|
+
declare function createCachePlugin(options?: CachePluginOptions): NeevPlugin;
|
|
86
|
+
declare const CachePlugin: NeevPlugin;
|
|
87
|
+
|
|
88
|
+
declare function createOfflinePlugin(): NeevPlugin;
|
|
89
|
+
declare const OfflinePlugin: NeevPlugin;
|
|
90
|
+
|
|
91
|
+
export { AuthClient, AuthPlugin, CachePlugin, Form, LoggerPlugin, NeevContext, NeevProvider, OfflinePlugin, Protected, Table, createCachePlugin, createClient, createOfflinePlugin, useAuth, useModel, useNeevClient, useSyncStatus };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NeevClientConfig, NeevClientInterface, AuthInterface, AuthUser, ModelRecord, UseModelReturn, SyncStatus, NeevPlugin } from '@neevjs/shared';
|
|
2
|
+
export { ApiMeta, ApiResponse, AuthInterface, AuthLoginResponse, AuthUser, ModelRecord, NeevClientConfig, NeevClientInterface, NeevPlugin, NeevRequest, Pagination, QueuedAction, RequestOptions, SyncStatus, UseModelReturn } from '@neevjs/shared';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
declare function createClient(config?: NeevClientConfig): NeevClientInterface;
|
|
6
|
+
|
|
7
|
+
declare const NeevContext: React.Context<NeevClientInterface | null>;
|
|
8
|
+
interface NeevProviderProps {
|
|
9
|
+
client: NeevClientInterface;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare function NeevProvider({ client, children }: NeevProviderProps): React.ReactElement;
|
|
13
|
+
declare function useNeevClient(): NeevClientInterface;
|
|
14
|
+
|
|
15
|
+
declare class AuthClient implements AuthInterface {
|
|
16
|
+
private client;
|
|
17
|
+
private userData;
|
|
18
|
+
constructor(client: NeevClientInterface);
|
|
19
|
+
login(email: string, password: string): Promise<void>;
|
|
20
|
+
register(email: string, password: string, name?: string): Promise<void>;
|
|
21
|
+
logout(): void;
|
|
22
|
+
user(): Promise<AuthUser | null>;
|
|
23
|
+
isAuthenticated(): boolean;
|
|
24
|
+
getToken(): string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare function useModel<T extends ModelRecord>(name: string): UseModelReturn<T>;
|
|
28
|
+
|
|
29
|
+
declare function useAuth(): AuthInterface;
|
|
30
|
+
|
|
31
|
+
declare function useSyncStatus(): SyncStatus;
|
|
32
|
+
|
|
33
|
+
interface TableColumn<T extends ModelRecord> {
|
|
34
|
+
key: keyof T & string;
|
|
35
|
+
label?: string;
|
|
36
|
+
render?: (value: T[keyof T], row: T) => React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
interface TableProps<T extends ModelRecord> {
|
|
39
|
+
model: string;
|
|
40
|
+
columns?: TableColumn<T>[];
|
|
41
|
+
onEdit?: (row: T) => void;
|
|
42
|
+
onDelete?: (row: T) => void;
|
|
43
|
+
emptyMessage?: string;
|
|
44
|
+
}
|
|
45
|
+
declare function Table<T extends ModelRecord>({ model, columns, onEdit, onDelete, emptyMessage, }: TableProps<T>): React.ReactElement;
|
|
46
|
+
|
|
47
|
+
interface FormField {
|
|
48
|
+
name: string;
|
|
49
|
+
label?: string;
|
|
50
|
+
type?: 'text' | 'email' | 'password' | 'number' | 'textarea' | 'select';
|
|
51
|
+
placeholder?: string;
|
|
52
|
+
required?: boolean;
|
|
53
|
+
options?: {
|
|
54
|
+
label: string;
|
|
55
|
+
value: string;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
interface FormProps<T extends ModelRecord> {
|
|
59
|
+
model: string;
|
|
60
|
+
fields?: FormField[];
|
|
61
|
+
initialValues?: Partial<T>;
|
|
62
|
+
editId?: number | string;
|
|
63
|
+
onSuccess?: () => void;
|
|
64
|
+
onError?: (err: Error) => void;
|
|
65
|
+
submitLabel?: string;
|
|
66
|
+
children?: React.ReactNode;
|
|
67
|
+
}
|
|
68
|
+
declare function Form<T extends ModelRecord>({ model, fields, initialValues, editId, onSuccess, onError, submitLabel, children, }: FormProps<T>): React.ReactElement;
|
|
69
|
+
|
|
70
|
+
interface ProtectedProps {
|
|
71
|
+
children: React.ReactNode;
|
|
72
|
+
fallback?: React.ReactNode;
|
|
73
|
+
role?: string;
|
|
74
|
+
}
|
|
75
|
+
declare function Protected({ children, fallback, role }: ProtectedProps): React.ReactElement;
|
|
76
|
+
|
|
77
|
+
declare const AuthPlugin: NeevPlugin;
|
|
78
|
+
|
|
79
|
+
declare const LoggerPlugin: NeevPlugin;
|
|
80
|
+
|
|
81
|
+
interface CachePluginOptions {
|
|
82
|
+
/** TTL in milliseconds. Default: 60_000 (1 minute) */
|
|
83
|
+
ttl?: number;
|
|
84
|
+
}
|
|
85
|
+
declare function createCachePlugin(options?: CachePluginOptions): NeevPlugin;
|
|
86
|
+
declare const CachePlugin: NeevPlugin;
|
|
87
|
+
|
|
88
|
+
declare function createOfflinePlugin(): NeevPlugin;
|
|
89
|
+
declare const OfflinePlugin: NeevPlugin;
|
|
90
|
+
|
|
91
|
+
export { AuthClient, AuthPlugin, CachePlugin, Form, LoggerPlugin, NeevContext, NeevProvider, OfflinePlugin, Protected, Table, createCachePlugin, createClient, createOfflinePlugin, useAuth, useModel, useNeevClient, useSyncStatus };
|