@lasterp/shared 1.0.0-alpha.3 → 1.0.0-alpha.5
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/node/index.d.ts +494 -21
- package/dist/node/index.js +492 -1
- package/dist/rn/index.d.ts +494 -21
- package/dist/rn/index.js +492 -1
- package/package.json +10 -2
package/dist/node/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface Item {
|
|
2
2
|
itemCode: string;
|
|
3
3
|
area: string;
|
|
4
|
-
|
|
4
|
+
model: string;
|
|
5
5
|
region: string;
|
|
6
6
|
grade: string;
|
|
7
7
|
gradeIssuer: string;
|
|
@@ -14,7 +14,7 @@ interface Item {
|
|
|
14
14
|
interface ItemVariant extends Item {
|
|
15
15
|
itemVariant: string;
|
|
16
16
|
}
|
|
17
|
-
interface
|
|
17
|
+
interface Model {
|
|
18
18
|
modelNumber: string;
|
|
19
19
|
simCardType: string;
|
|
20
20
|
connectivity: string;
|
|
@@ -24,20 +24,492 @@ interface Colour {
|
|
|
24
24
|
hex: string;
|
|
25
25
|
colorSystem: string;
|
|
26
26
|
}
|
|
27
|
+
import { FrappeApp, FrappeAuth, FrappeCall } from "frappe-js-sdk";
|
|
28
|
+
import { FrappeDB } from "frappe-js-sdk/lib/db";
|
|
29
|
+
import { FrappeFileUpload } from "frappe-js-sdk/lib/file";
|
|
30
|
+
import { Socket } from "socket.io-client";
|
|
31
|
+
interface FrappeConfig {
|
|
32
|
+
/** The URL of your Frappe server */
|
|
33
|
+
url: string;
|
|
34
|
+
tokenParams?: TokenParams;
|
|
35
|
+
app: FrappeApp;
|
|
36
|
+
auth: FrappeAuth;
|
|
37
|
+
db: FrappeDB;
|
|
38
|
+
call: FrappeCall;
|
|
39
|
+
file: FrappeFileUpload;
|
|
40
|
+
socket?: Socket;
|
|
41
|
+
enableSocket?: boolean;
|
|
42
|
+
socketPort?: string;
|
|
43
|
+
}
|
|
44
|
+
interface TokenParams {
|
|
45
|
+
/** Whether to use token for API calls */
|
|
46
|
+
useToken: boolean;
|
|
47
|
+
/** Function that returns the token as a string - this could be fetched from LocalStorage or auth providers like Firebase, Auth0 etc. */
|
|
48
|
+
token?: () => string;
|
|
49
|
+
/** Type of token to be used for authentication */
|
|
50
|
+
type: "Bearer" | "token";
|
|
51
|
+
}
|
|
52
|
+
import { PropsWithChildren } from "react";
|
|
53
|
+
type FrappeProviderProps = PropsWithChildren<{
|
|
54
|
+
/** URL of the Frappe server
|
|
55
|
+
*
|
|
56
|
+
* Only needed if the URL of the window is not the same as the Frappe server URL */
|
|
57
|
+
url?: string;
|
|
58
|
+
/** Token parameters to be used for authentication
|
|
59
|
+
*
|
|
60
|
+
* Only needed for token based authentication */
|
|
61
|
+
tokenParams?: TokenParams;
|
|
62
|
+
/** Flag to disable socket, if needed. This defaults to true. */
|
|
63
|
+
enableSocket?: boolean;
|
|
64
|
+
/** Port on which Socket is running. Only meant for local development. Set to undefined on production. */
|
|
65
|
+
socketPort?: string;
|
|
66
|
+
/** Get this from frappe.local.site on the server, or frappe.boot.sitename on the window.
|
|
67
|
+
* Required for Socket connection to work in Frappe v15+
|
|
68
|
+
*/
|
|
69
|
+
siteName?: string;
|
|
70
|
+
/** Custom Headers to be passed in each request */
|
|
71
|
+
customHeaders?: object;
|
|
72
|
+
}>;
|
|
73
|
+
declare const FrappeContext: React.Context<null | FrappeConfig>;
|
|
74
|
+
declare const FrappeProvider: React.FC<FrappeProviderProps>;
|
|
75
|
+
import { AuthCredentials, AuthResponse } from "frappe-js-sdk/lib/auth/types";
|
|
76
|
+
/**
|
|
77
|
+
* Hook to start listening to user state and provides functions to login/logout
|
|
78
|
+
*
|
|
79
|
+
* @param options - [Optional] SWRConfiguration options for fetching current logged in user
|
|
80
|
+
* @returns Returns an object with the following properties: currentUser, loading, error, and functions to login, logout and updateCurrentUser
|
|
81
|
+
*/
|
|
82
|
+
declare const useFrappeAuth: () => {
|
|
83
|
+
/** The current logged in user. Will be null/undefined if user is not logged in */
|
|
84
|
+
currentUser: string | null | undefined;
|
|
85
|
+
/** Will be true when the hook is fetching user data */
|
|
86
|
+
isLoading: boolean;
|
|
87
|
+
/** Will be true when the hook is fetching (or revalidating) the user state. (Refer to isValidating in useSWR) */
|
|
88
|
+
isValidating: boolean;
|
|
89
|
+
/** Error object returned from API call */
|
|
90
|
+
error: Error | null | undefined;
|
|
91
|
+
/** Function to login the user with email and password */
|
|
92
|
+
login: (credentials: AuthCredentials) => Promise<AuthResponse>;
|
|
93
|
+
/** Function to log the user out */
|
|
94
|
+
logout: () => Promise<any>;
|
|
95
|
+
/** Function to fetch updated user state */
|
|
96
|
+
updateCurrentUser: () => void;
|
|
97
|
+
/** Function to get the user cookie and */
|
|
98
|
+
getUserCookie: () => void;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Hook to make a GET request to the server
|
|
102
|
+
*
|
|
103
|
+
* @param method - name of the method to call (will be dotted path e.g. "frappe.client.get_list")
|
|
104
|
+
* @param params - parameters to pass to the method
|
|
105
|
+
* @param options - optional query options
|
|
106
|
+
* @param type - type of the request to make - defaults to GET
|
|
107
|
+
*
|
|
108
|
+
* @typeParam T - Type of the data returned by the method
|
|
109
|
+
* @returns an object with the following properties: data, error, isLoading, isFetching, and refetch
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
*
|
|
113
|
+
* const { data, error, isLoading } = useFrappeGetCall("ping")
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
declare const useFrappeGetCall: <T = any>(method: string, params?: Record<string, any>, options?: {
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
staleTime?: number;
|
|
119
|
+
retry?: boolean | number;
|
|
120
|
+
}, type?: "GET" | "POST") => {
|
|
121
|
+
data: T | undefined;
|
|
122
|
+
error: Error | null;
|
|
123
|
+
isLoading: boolean;
|
|
124
|
+
isFetching: boolean;
|
|
125
|
+
refetch: () => void;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @param method - name of the method to call (POST request) (will be dotted path e.g. "frappe.client.set_value")
|
|
130
|
+
* @returns an object with the following properties: loading, error, isCompleted , result, and call and reset functions
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* const { call, result, loading, error, isCompleted, reset } = useFrappePostCall("frappe.client.set_value")
|
|
135
|
+
*
|
|
136
|
+
* const onSubmit = async () => {
|
|
137
|
+
* const message = await call({ doctype: "User", docname: "test@example.com", fieldname: "full_name", value: "John Doe" })
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
*/
|
|
141
|
+
declare const useFrappePostCall: unknown;
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @param method - name of the method to call (PUT request) (will be dotted path e.g. "frappe.client.set_value")
|
|
145
|
+
* @returns an object with the following properties: loading, error, isCompleted , result, and call and reset functions
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
*
|
|
149
|
+
* const { call, result, loading, error, isCompleted, reset } = useFrappePutCall("frappe.client.set_value")
|
|
150
|
+
*
|
|
151
|
+
* const onSubmit = async () => {
|
|
152
|
+
* const message = await call({ doctype: "User", docname: "test@example.com", fieldname: "full_name", value: "John Doe" })
|
|
153
|
+
* }
|
|
154
|
+
*/
|
|
155
|
+
declare const useFrappePutCall: unknown;
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param method - name of the method to call (DELETE request) (will be dotted path e.g. "frappe.client.delete")
|
|
159
|
+
* @returns an object with the following properties: loading, error, isCompleted , result, and call and reset functions
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
*
|
|
163
|
+
* const { call, result, loading, error, isCompleted, reset } = useFrappeDeleteCall("frappe.client.delete")
|
|
164
|
+
*
|
|
165
|
+
* const onSubmit = async () => {
|
|
166
|
+
* const message = await call({ doctype: "User", docname: "test@example.com" })
|
|
167
|
+
* }
|
|
168
|
+
*/
|
|
169
|
+
declare const useFrappeDeleteCall: unknown;
|
|
170
|
+
import { Filter } from "frappe-js-sdk/lib/db/types";
|
|
171
|
+
/**
|
|
172
|
+
* Hook to fetch number of documents from the database
|
|
173
|
+
*
|
|
174
|
+
*
|
|
175
|
+
* @param doctype - The doctype to fetch
|
|
176
|
+
* @param filters - filters to apply to the query
|
|
177
|
+
* @param debug - Whether to log debug messages or not. Defaults to false
|
|
178
|
+
* @param options [Optional] SWRConfiguration options for fetching data
|
|
179
|
+
* @returns an object (SWRResponse) with the following properties: data (number), error, isValidating, and mutate
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
*
|
|
183
|
+
* const { data, error, isLoading, mutate } = useFrappeGetDocCount("User")
|
|
184
|
+
*
|
|
185
|
+
*/
|
|
186
|
+
declare const useFrappeGetDocCount: <T = any>(doctype: string, filters?: Filter<T>[], debug?: boolean, options?: {
|
|
187
|
+
staleTime?: number;
|
|
188
|
+
retry?: boolean | number;
|
|
189
|
+
}) => {
|
|
190
|
+
data: number | undefined;
|
|
191
|
+
error: Error | null;
|
|
192
|
+
isLoading: boolean;
|
|
193
|
+
isFetching: boolean;
|
|
194
|
+
refetch: () => void;
|
|
195
|
+
};
|
|
196
|
+
import { FrappeDoc } from "frappe-js-sdk/lib/db/types";
|
|
197
|
+
/**
|
|
198
|
+
* Hook to create a document in the database and maintain loading and error states
|
|
199
|
+
* @returns Object with the following properties: loading, error, isCompleted and createDoc and reset functions
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
*
|
|
203
|
+
* const { createDoc, loading, error, isCompleted, reset } = useFrappeCreateDoc()
|
|
204
|
+
*
|
|
205
|
+
* const onSubmit = async () => {
|
|
206
|
+
* const doc = await createDoc("User", { name: "John Doe", email: "john.doe@example.com" })
|
|
207
|
+
* }
|
|
208
|
+
*/
|
|
209
|
+
declare const useFrappeCreateDoc: <T = any>() => {
|
|
210
|
+
createDoc: (doctype: string, doc: T) => Promise<FrappeDoc<T>>;
|
|
211
|
+
loading: boolean;
|
|
212
|
+
error: Error | null | undefined;
|
|
213
|
+
isCompleted: boolean;
|
|
214
|
+
reset: () => void;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Hook to delete a document in the database and maintain loading and error states
|
|
218
|
+
* @returns Object with the following properties: loading, error, isCompleted and deleteDoc and reset functions
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* const { deleteDoc, loading, error, isCompleted, reset } = useFrappeDeleteDoc()
|
|
223
|
+
*
|
|
224
|
+
* const onDelete = async () => {
|
|
225
|
+
* const message = await deleteDoc("User", "test@example.com")
|
|
226
|
+
* }
|
|
227
|
+
*/
|
|
228
|
+
declare const useFrappeDeleteDoc: <T = any>() => {
|
|
229
|
+
deleteDoc: (doctype: string, docname?: string | null) => Promise<{
|
|
230
|
+
message: string;
|
|
231
|
+
}>;
|
|
232
|
+
loading: boolean;
|
|
233
|
+
error: Error | null | undefined;
|
|
234
|
+
isCompleted: boolean;
|
|
235
|
+
reset: () => void;
|
|
236
|
+
};
|
|
237
|
+
/** useFrappeEventListener hook for listening to events from the server
|
|
238
|
+
* @param eventName - name of the event to listen to
|
|
239
|
+
* @param callback - callback function to be called when the event is triggered. The callback function will receive the data sent from the server. It is recommended to memoize this function.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* useFrappeEventListener('my_event', (data) => {
|
|
244
|
+
* // do something with the data
|
|
245
|
+
* if(data.status === 'success') {
|
|
246
|
+
* console.log('success')
|
|
247
|
+
* }
|
|
248
|
+
* })
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare const useFrappeEventListener: <T = any>(eventName: string, callback: (eventData: T) => void) => void;
|
|
252
|
+
interface ViewerEventData {
|
|
253
|
+
doctype: string;
|
|
254
|
+
docname: string;
|
|
255
|
+
users: string[];
|
|
256
|
+
}
|
|
257
|
+
interface DocumentUpdateEventData {
|
|
258
|
+
doctype: string;
|
|
259
|
+
name: string;
|
|
260
|
+
modified: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Hook for listening to document events.
|
|
264
|
+
* The hook will automatically subscribe to the document room, and unsubscribe when the component unmounts.
|
|
265
|
+
* The hook listens to the following events:
|
|
266
|
+
* - doc_update: This is triggered when the document is updated. The callback function will receive the updated document.
|
|
267
|
+
* - doc_viewers: This is triggered when the list of viewers of the document changes. The hook will update the viewers state with the list of viewers.
|
|
268
|
+
*
|
|
269
|
+
* @param doctype Name of the doctype
|
|
270
|
+
* @param docname Name of the document
|
|
271
|
+
* @param emitOpenCloseEventsOnMount [Optional] If true, the hook will emit doc_open and doc_close events on mount and unmount respectively. Defaults to true.
|
|
272
|
+
* @param onUpdateCallback Function to be called when the document is updated. It is recommended to memoize this function.
|
|
273
|
+
* @returns viewers - array of userID's, emitDocOpen - function to emit doc_open event, emitDocClose - function to emit doc_close event
|
|
274
|
+
*/
|
|
275
|
+
declare const useFrappeDocumentEventListener: (doctype: string, docname: string, onUpdateCallback: (eventData: DocumentUpdateEventData) => void, emitOpenCloseEventsOnMount?: boolean) => {
|
|
276
|
+
viewers: string[];
|
|
277
|
+
emitDocOpen: () => void;
|
|
278
|
+
emitDocClose: () => void;
|
|
279
|
+
};
|
|
280
|
+
interface DocTypeListUpdateEventData {
|
|
281
|
+
doctype: string;
|
|
282
|
+
name: string;
|
|
283
|
+
user: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Hook for listening to doctype events.
|
|
287
|
+
* The hook will automatically subscribe to the doctype room, and unsubscribe when the component unmounts.
|
|
288
|
+
* The hook listens to the following event:
|
|
289
|
+
* - list_update: This is triggered when a document of the doctype is updated (created, modified or deleted). The callback function will receive the updated document.
|
|
290
|
+
*
|
|
291
|
+
* @param doctype Name of the doctype
|
|
292
|
+
* @param onListUpdateCallback Function to be called when the document is updated. It is recommended to memoize this function.
|
|
293
|
+
*/
|
|
294
|
+
declare const useFrappeDocTypeEventListener: (doctype: string, onListUpdateCallback: (eventData: DocTypeListUpdateEventData) => void) => void;
|
|
295
|
+
import { FileArgs } from "frappe-js-sdk/lib/file/types";
|
|
296
|
+
interface FrappeFileUploadResponse {
|
|
297
|
+
/** Name of the file document in the database */
|
|
298
|
+
name: string;
|
|
299
|
+
owner: string;
|
|
300
|
+
creation: string;
|
|
301
|
+
modified: string;
|
|
302
|
+
modified_by: string;
|
|
303
|
+
docstatus: 0 | 1 | 2;
|
|
304
|
+
idx: number;
|
|
305
|
+
/** Name of the uploaded file */
|
|
306
|
+
file_name: string;
|
|
307
|
+
/** File is not accessible by guest users */
|
|
308
|
+
is_private: 1 | 0;
|
|
309
|
+
is_home_folder: 0 | 1;
|
|
310
|
+
is_attachments_folder: 0 | 1;
|
|
311
|
+
/** File size in bytes */
|
|
312
|
+
file_size: number;
|
|
313
|
+
/** Path of the file ex: /private/files/file_name.jpg */
|
|
314
|
+
file_url: string;
|
|
315
|
+
folder: string;
|
|
316
|
+
is_folder: 0 | 1;
|
|
317
|
+
/** Doctype the file is linked to */
|
|
318
|
+
attached_to_doctype: string;
|
|
319
|
+
/** Document the file is linked to */
|
|
320
|
+
attached_to_name: string;
|
|
321
|
+
content_hash: string;
|
|
322
|
+
uploaded_to_dropbox: 0 | 1;
|
|
323
|
+
uploaded_to_google_drive: 0 | 1;
|
|
324
|
+
doctype: "File";
|
|
325
|
+
}
|
|
326
|
+
interface UseFrappeFileUploadReturnType<T = any> {
|
|
327
|
+
/** Function to upload the file */
|
|
328
|
+
upload: (file: File, args: FileArgs<T>, apiPath?: string) => Promise<FrappeFileUploadResponse>;
|
|
329
|
+
/** Upload Progress in % - rounded off */
|
|
330
|
+
progress: number;
|
|
331
|
+
/** Will be true when the file is being uploaded */
|
|
332
|
+
loading: boolean;
|
|
333
|
+
/** Error object returned from API call */
|
|
334
|
+
error: Error | null;
|
|
335
|
+
/** Will be true if file upload is successful. Else false */
|
|
336
|
+
isCompleted: boolean;
|
|
337
|
+
/** Function to reset the state of the hook */
|
|
338
|
+
reset: () => void;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Hook to upload files to the server
|
|
342
|
+
*
|
|
343
|
+
* @returns an object with the following properties: loading, error, isCompleted , result, and call and reset functions
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
*
|
|
347
|
+
* const { upload, progress, loading, error, isCompleted, reset } = useFrappeFileUpload()
|
|
348
|
+
*
|
|
349
|
+
* const onSubmit = async () => {
|
|
350
|
+
* const message = await upload(myFile, { doctype: "User", docname: "test@example.com", fieldname: "profile_pic", is_private: 1 })
|
|
351
|
+
* }
|
|
352
|
+
*/
|
|
353
|
+
declare const useFrappeFileUpload: <T = any>() => UseFrappeFileUploadReturnType<T>;
|
|
354
|
+
import { FrappeDoc as FrappeDoc2 } from "frappe-js-sdk/lib/db/types";
|
|
355
|
+
/**
|
|
356
|
+
* Hook to fetch a document from the database
|
|
357
|
+
*
|
|
358
|
+
*
|
|
359
|
+
* @param doctype - The doctype to fetch
|
|
360
|
+
* @param name - the name of the document to fetch
|
|
361
|
+
* @param options [Optional] SWRConfiguration options for fetching data
|
|
362
|
+
* @returns an object (SWRResponse) with the following properties: data, error, isValidating, and mutate
|
|
363
|
+
*
|
|
364
|
+
* @typeParam T - The type of the document
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
*
|
|
368
|
+
* const { data, error, isLoading, mutate } = useFrappeGetDoc("User", "test")
|
|
369
|
+
*
|
|
370
|
+
* if (isLoading) {
|
|
371
|
+
* return <div>Loading...</div>
|
|
372
|
+
* }
|
|
373
|
+
*
|
|
374
|
+
* if (error) {
|
|
375
|
+
* return <div>Error: {error.message}</div>
|
|
376
|
+
* }
|
|
377
|
+
*
|
|
378
|
+
* return <div>{data?.name} - {data?.email}</div>
|
|
379
|
+
*/
|
|
380
|
+
declare const useFrappeGetDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
381
|
+
staleTime?: number;
|
|
382
|
+
retry?: boolean | number;
|
|
383
|
+
}) => {
|
|
384
|
+
data: FrappeDoc2<T> | undefined;
|
|
385
|
+
error: Error | null;
|
|
386
|
+
isLoading: boolean;
|
|
387
|
+
isFetching: boolean;
|
|
388
|
+
refetch: () => void;
|
|
389
|
+
};
|
|
390
|
+
import { FrappeDoc as FrappeDoc3, GetDocListArgs } from "frappe-js-sdk/lib/db/types";
|
|
391
|
+
/**
|
|
392
|
+
* Hook to fetch a list of documents from the database
|
|
393
|
+
*
|
|
394
|
+
* @param doctype Name of the doctype to fetch
|
|
395
|
+
* @param args Arguments to pass (filters, pagination, etc)
|
|
396
|
+
* @param options [Optional] SWRConfiguration options for fetching data
|
|
397
|
+
* @returns an object (SWRResponse) with the following properties: data, error, isValidating, and mutate
|
|
398
|
+
*
|
|
399
|
+
* @typeParam T - The type definition of the document object
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
*
|
|
403
|
+
* const { data, error, isLoading, mutate } = useFrappeGetDocList("User")
|
|
404
|
+
*
|
|
405
|
+
* if (isLoading) {
|
|
406
|
+
* return <div>Loading...</div>
|
|
407
|
+
* }
|
|
408
|
+
*
|
|
409
|
+
* if (error) {
|
|
410
|
+
* return <div>Error: {error.message}</div>
|
|
411
|
+
* }
|
|
412
|
+
*
|
|
413
|
+
* return <ul>{data?.map((user) => <li key={user.name}>{user.name}</li>)}</ul>
|
|
414
|
+
*
|
|
415
|
+
*/
|
|
416
|
+
declare const useFrappeGetDocList: <
|
|
417
|
+
T = any,
|
|
418
|
+
K = FrappeDoc3<T>
|
|
419
|
+
>(doctype: string, args?: GetDocListArgs<K>, options?: {
|
|
420
|
+
staleTime?: number;
|
|
421
|
+
retry?: boolean | number;
|
|
422
|
+
}) => {
|
|
423
|
+
data: T[] | undefined;
|
|
424
|
+
error: Error | null;
|
|
425
|
+
isLoading: boolean;
|
|
426
|
+
isFetching: boolean;
|
|
427
|
+
refetch: () => void;
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* Hook to prefetch a document from the database
|
|
431
|
+
* @param doctype - The doctype to fetch
|
|
432
|
+
* @param name - The name of the document to fetch
|
|
433
|
+
* @param swrKey - The SWRKey to use for caching the result - optional
|
|
434
|
+
* @param options - The SWRConfiguration options for fetching data
|
|
435
|
+
* @returns A function to prefetch the document
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
*
|
|
439
|
+
* const preloadDoc = useFrappePrefetchDoc("User", "test@example.com")
|
|
440
|
+
*
|
|
441
|
+
* // Call the function when you want to prefetch the document
|
|
442
|
+
* const onHover = () => {
|
|
443
|
+
* preloadDoc()
|
|
444
|
+
* }
|
|
445
|
+
*/
|
|
446
|
+
declare const useFrappePrefetchDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
447
|
+
staleTime?: number;
|
|
448
|
+
}) => (() => void);
|
|
449
|
+
import { Filter as Filter2 } from "frappe-js-sdk/lib/db/types";
|
|
450
|
+
interface SearchResult {
|
|
451
|
+
value: string;
|
|
452
|
+
label: string;
|
|
453
|
+
description: string;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Hook to search for documents - only works with Frappe v15+
|
|
457
|
+
*
|
|
458
|
+
* @param doctype - name of the doctype (table) where we are performing our search
|
|
459
|
+
* @param text - search text
|
|
460
|
+
* @param filters - (optional) the results will be filtered based on these
|
|
461
|
+
* @param limit - (optional) the number of results to return. Defaults to 20
|
|
462
|
+
* @param debounce - (optional) the number of milliseconds to wait before making the API call. Defaults to 250ms.
|
|
463
|
+
* @returns result - array of type SearchResult with a list of suggestions based on search text
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* const [searchText, setSearchText] = useState("")
|
|
468
|
+
* const { data, error, isLoading, mutate } = useSearch("User", searchText)
|
|
469
|
+
*/
|
|
470
|
+
declare const useSearch: (doctype: string, text: string, filters?: Filter2[], limit?: number, debounce?: number) => {
|
|
471
|
+
data: {
|
|
472
|
+
message: SearchResult[];
|
|
473
|
+
} | undefined;
|
|
474
|
+
error: Error | null;
|
|
475
|
+
isLoading: boolean;
|
|
476
|
+
isFetching: boolean;
|
|
477
|
+
refetch: () => void;
|
|
478
|
+
};
|
|
479
|
+
import { FrappeDoc as FrappeDoc4 } from "frappe-js-sdk/lib/db/types";
|
|
480
|
+
/**
|
|
481
|
+
* Hook to update a document in the database and maintain loading and error states
|
|
482
|
+
* @returns Object with the following properties: loading, error, isCompleted and updateDoc and reset functions
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
*
|
|
486
|
+
* const { updateDoc, loading, error, isCompleted, reset } = useFrappeUpdateDoc()
|
|
487
|
+
*
|
|
488
|
+
* const onSubmit = async () => {
|
|
489
|
+
* const doc = await updateDoc("User", "test@example.com", { name: "John Doe", email: "john.doe@example.com" })
|
|
490
|
+
* }
|
|
491
|
+
*/
|
|
492
|
+
declare const useFrappeUpdateDoc: <T = any>() => {
|
|
493
|
+
updateDoc: (doctype: string, docname: string | null, doc: Partial<T>) => Promise<FrappeDoc4<T>>;
|
|
494
|
+
loading: boolean;
|
|
495
|
+
error: Error | null | undefined;
|
|
496
|
+
isCompleted: boolean;
|
|
497
|
+
reset: () => void;
|
|
498
|
+
};
|
|
27
499
|
interface Globals {
|
|
28
500
|
header: Header;
|
|
29
501
|
footer: Footer;
|
|
30
502
|
}
|
|
31
503
|
interface Brand {
|
|
32
|
-
brandImage
|
|
504
|
+
brandImage?: string;
|
|
33
505
|
}
|
|
34
506
|
interface NavbarItem {
|
|
35
507
|
label: string;
|
|
36
508
|
enableDropdown: boolean;
|
|
37
509
|
enableLink: boolean;
|
|
38
|
-
link
|
|
39
|
-
dropdownDescription
|
|
40
|
-
groups
|
|
510
|
+
link?: string;
|
|
511
|
+
dropdownDescription?: string;
|
|
512
|
+
groups?: NavbarSubItemGroup[];
|
|
41
513
|
}
|
|
42
514
|
interface NavbarSubItemGroup {
|
|
43
515
|
title: string;
|
|
@@ -45,22 +517,22 @@ interface NavbarSubItemGroup {
|
|
|
45
517
|
}
|
|
46
518
|
interface NavbarSubItem {
|
|
47
519
|
label: string;
|
|
48
|
-
description
|
|
49
|
-
image
|
|
50
|
-
link
|
|
520
|
+
description?: string;
|
|
521
|
+
image?: string;
|
|
522
|
+
link?: string;
|
|
51
523
|
}
|
|
52
524
|
interface Topbar {
|
|
53
525
|
topbarEnabled: boolean;
|
|
54
526
|
items: TopbarItem[];
|
|
55
527
|
}
|
|
56
528
|
interface TopbarItem {
|
|
57
|
-
icon
|
|
529
|
+
icon?: string;
|
|
58
530
|
label: string;
|
|
59
|
-
link
|
|
531
|
+
link?: string;
|
|
60
532
|
}
|
|
61
533
|
interface Header {
|
|
62
534
|
brand: Brand;
|
|
63
|
-
headerType
|
|
535
|
+
headerType?: string;
|
|
64
536
|
tabs: NavbarItem[];
|
|
65
537
|
topbar: Topbar;
|
|
66
538
|
}
|
|
@@ -70,16 +542,16 @@ interface FooterItemGroup {
|
|
|
70
542
|
}
|
|
71
543
|
interface FooterItem {
|
|
72
544
|
label: string;
|
|
73
|
-
link
|
|
545
|
+
link?: string;
|
|
74
546
|
}
|
|
75
547
|
interface Footer {
|
|
76
|
-
footerType
|
|
548
|
+
footerType?: string;
|
|
77
549
|
groups: FooterItemGroup[];
|
|
78
|
-
copyright
|
|
79
|
-
address
|
|
80
|
-
country
|
|
81
|
-
phone
|
|
82
|
-
email
|
|
550
|
+
copyright?: string;
|
|
551
|
+
address?: string;
|
|
552
|
+
country?: string;
|
|
553
|
+
phone?: string;
|
|
554
|
+
email?: string;
|
|
83
555
|
}
|
|
84
556
|
interface Hero {
|
|
85
557
|
type: string;
|
|
@@ -91,8 +563,9 @@ interface Block {
|
|
|
91
563
|
}
|
|
92
564
|
interface Page {
|
|
93
565
|
slug: string;
|
|
94
|
-
hero
|
|
566
|
+
hero?: Hero;
|
|
95
567
|
blocks: Block[];
|
|
96
568
|
}
|
|
569
|
+
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
97
570
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
98
|
-
export { equalsIgnoreCase, TopbarItem, Topbar, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem,
|
|
571
|
+
export { useSearch, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, ViewerEventData, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, SearchResult, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeFileUploadResponse, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Brand, Block };
|