@panneau/data 4.1.0 → 5.0.0-alpha.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.
Files changed (42) hide show
  1. package/README.md +65 -0
  2. package/dist/adapter.d.ts +84 -0
  3. package/dist/adapter.d.ts.map +1 -0
  4. package/dist/errors.d.ts +51 -0
  5. package/dist/errors.d.ts.map +1 -0
  6. package/dist/errors.js +78 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/index.d.ts +4 -456
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +3 -1794
  11. package/dist/laravel/index.d.ts +17 -0
  12. package/dist/laravel/index.d.ts.map +1 -0
  13. package/dist/laravel/index.js +37 -0
  14. package/dist/laravel/index.js.map +1 -0
  15. package/dist/query/context.d.ts +15 -0
  16. package/dist/query/context.d.ts.map +1 -0
  17. package/dist/query/context.js +34 -0
  18. package/dist/query/context.js.map +1 -0
  19. package/dist/query/hooks.d.ts +52 -0
  20. package/dist/query/hooks.d.ts.map +1 -0
  21. package/dist/query/hooks.js +299 -0
  22. package/dist/query/hooks.js.map +1 -0
  23. package/dist/query/index.d.ts +6 -0
  24. package/dist/query/index.d.ts.map +1 -0
  25. package/dist/query/index.js +6 -0
  26. package/dist/query/keys.d.ts +17 -0
  27. package/dist/query/keys.d.ts.map +1 -0
  28. package/dist/query/keys.js +55 -0
  29. package/dist/query/keys.js.map +1 -0
  30. package/dist/query/options.d.ts +18 -0
  31. package/dist/query/options.d.ts.map +1 -0
  32. package/dist/query/options.js +30 -0
  33. package/dist/query/options.js.map +1 -0
  34. package/dist/query/refresh.d.ts +12 -0
  35. package/dist/query/refresh.d.ts.map +1 -0
  36. package/dist/query/refresh.js +24 -0
  37. package/dist/query/refresh.js.map +1 -0
  38. package/dist/rest.d.ts +25 -0
  39. package/dist/rest.d.ts.map +1 -0
  40. package/dist/rest.js +243 -0
  41. package/dist/rest.js.map +1 -0
  42. package/package.json +40 -55
package/dist/index.d.ts CHANGED
@@ -1,456 +1,4 @@
1
- import * as _tanstack_react_query from '@tanstack/react-query';
2
- import { UseQueryOptions, UseMutationOptions, QueryClientConfig, QueryClient } from '@tanstack/react-query';
3
- import { Item, Pagination, Resource, ResourceItem, Media } from '@panneau/core';
4
- import * as react from 'react';
5
- import { ReactNode } from 'react';
6
-
7
- declare function useItem<T = Item>(scope: any, id: any, loader: (id: any) => Promise<T>, opts?: any): {
8
- error: Error;
9
- isError: true;
10
- isPending: false;
11
- isLoading: false;
12
- isLoadingError: false;
13
- isRefetchError: true;
14
- isSuccess: false;
15
- isPlaceholderData: false;
16
- status: "error";
17
- dataUpdatedAt: number;
18
- errorUpdatedAt: number;
19
- failureCount: number;
20
- failureReason: Error;
21
- errorUpdateCount: number;
22
- isFetched: boolean;
23
- isFetchedAfterMount: boolean;
24
- isFetching: boolean;
25
- isInitialLoading: boolean;
26
- isPaused: boolean;
27
- isRefetching: boolean;
28
- isStale: boolean;
29
- isEnabled: boolean;
30
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<T, Error>>;
31
- fetchStatus: _tanstack_react_query.FetchStatus;
32
- item: T;
33
- } | {
34
- error: null;
35
- isError: false;
36
- isPending: false;
37
- isLoading: false;
38
- isLoadingError: false;
39
- isRefetchError: false;
40
- isSuccess: true;
41
- isPlaceholderData: false;
42
- status: "success";
43
- dataUpdatedAt: number;
44
- errorUpdatedAt: number;
45
- failureCount: number;
46
- failureReason: Error;
47
- errorUpdateCount: number;
48
- isFetched: boolean;
49
- isFetchedAfterMount: boolean;
50
- isFetching: boolean;
51
- isInitialLoading: boolean;
52
- isPaused: boolean;
53
- isRefetching: boolean;
54
- isStale: boolean;
55
- isEnabled: boolean;
56
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<T, Error>>;
57
- fetchStatus: _tanstack_react_query.FetchStatus;
58
- item: T;
59
- };
60
-
61
- type UseItemsResponse<T> = {
62
- data: T[];
63
- pagination: Pagination;
64
- meta?: Pagination;
65
- } | T[];
66
- type UseItemsKey = [string, Record<string, unknown> | null, number | null, number | null];
67
- type Query = {
68
- page?: number | null;
69
- count?: number | null;
70
- [key: string]: unknown;
71
- };
72
- type UseItemsOptions<T> = Omit<UseQueryOptions<UseItemsResponse<T>, Error, UseItemsResponse<T>, UseItemsKey>, 'queryKey' | 'queryFn'> & {
73
- url?: string | null;
74
- getItems?: ((query: Record<string, unknown> | null, page: number | null, count: number | null) => Promise<UseItemsResponse<T>>) | null;
75
- page?: number | null;
76
- count?: number | null;
77
- query?: Query | null;
78
- keepData?: boolean;
79
- };
80
- declare function useItems<T = Item>(scope: string, { url, getItems, page: initialPage, count: initialCount, query, keepData, ...queryConfig }: UseItemsOptions<T>): {
81
- isLoading: boolean;
82
- isFetching: boolean;
83
- isRefetching: boolean;
84
- isFetched: boolean;
85
- isPlaceholderData: boolean;
86
- items: any;
87
- pages: {};
88
- allItems: any;
89
- loading: boolean;
90
- loaded: boolean;
91
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
92
- updateItem: (item: any) => void;
93
- pagination: {
94
- page: number;
95
- lastPage: number;
96
- total: number;
97
- };
98
- error: Error;
99
- isError: true;
100
- isPending: false;
101
- isLoadingError: false;
102
- isRefetchError: true;
103
- isSuccess: false;
104
- status: "error";
105
- dataUpdatedAt: number;
106
- errorUpdatedAt: number;
107
- failureCount: number;
108
- failureReason: Error;
109
- errorUpdateCount: number;
110
- isFetchedAfterMount: boolean;
111
- isInitialLoading: boolean;
112
- isPaused: boolean;
113
- isStale: boolean;
114
- isEnabled: boolean;
115
- fetchStatus: _tanstack_react_query.FetchStatus;
116
- } | {
117
- isLoading: boolean;
118
- isFetching: boolean;
119
- isRefetching: boolean;
120
- isFetched: boolean;
121
- isPlaceholderData: boolean;
122
- items: any;
123
- pages: {};
124
- allItems: any;
125
- loading: boolean;
126
- loaded: boolean;
127
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
128
- updateItem: (item: any) => void;
129
- pagination: {
130
- page: number;
131
- lastPage: number;
132
- total: number;
133
- };
134
- error: null;
135
- isError: false;
136
- isPending: false;
137
- isLoadingError: false;
138
- isRefetchError: false;
139
- isSuccess: true;
140
- status: "success";
141
- dataUpdatedAt: number;
142
- errorUpdatedAt: number;
143
- failureCount: number;
144
- failureReason: Error;
145
- errorUpdateCount: number;
146
- isFetchedAfterMount: boolean;
147
- isInitialLoading: boolean;
148
- isPaused: boolean;
149
- isStale: boolean;
150
- isEnabled: boolean;
151
- fetchStatus: _tanstack_react_query.FetchStatus;
152
- } | {
153
- isLoading: boolean;
154
- isFetching: boolean;
155
- isRefetching: boolean;
156
- isFetched: boolean;
157
- isPlaceholderData: boolean;
158
- items: any;
159
- pages: {};
160
- allItems: any;
161
- loading: boolean;
162
- loaded: boolean;
163
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
164
- updateItem: (item: any) => void;
165
- pagination: {
166
- page: number;
167
- lastPage: number;
168
- total: number;
169
- };
170
- error: Error;
171
- isError: true;
172
- isPending: false;
173
- isLoadingError: true;
174
- isRefetchError: false;
175
- isSuccess: false;
176
- status: "error";
177
- dataUpdatedAt: number;
178
- errorUpdatedAt: number;
179
- failureCount: number;
180
- failureReason: Error;
181
- errorUpdateCount: number;
182
- isFetchedAfterMount: boolean;
183
- isInitialLoading: boolean;
184
- isPaused: boolean;
185
- isStale: boolean;
186
- isEnabled: boolean;
187
- fetchStatus: _tanstack_react_query.FetchStatus;
188
- } | {
189
- isLoading: boolean;
190
- isFetching: boolean;
191
- isRefetching: boolean;
192
- isFetched: boolean;
193
- isPlaceholderData: boolean;
194
- items: any;
195
- pages: {};
196
- allItems: any;
197
- loading: boolean;
198
- loaded: boolean;
199
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
200
- updateItem: (item: any) => void;
201
- pagination: {
202
- page: number;
203
- lastPage: number;
204
- total: number;
205
- };
206
- error: null;
207
- isError: false;
208
- isPending: true;
209
- isLoadingError: false;
210
- isRefetchError: false;
211
- isSuccess: false;
212
- status: "pending";
213
- dataUpdatedAt: number;
214
- errorUpdatedAt: number;
215
- failureCount: number;
216
- failureReason: Error;
217
- errorUpdateCount: number;
218
- isFetchedAfterMount: boolean;
219
- isInitialLoading: boolean;
220
- isPaused: boolean;
221
- isStale: boolean;
222
- isEnabled: boolean;
223
- fetchStatus: _tanstack_react_query.FetchStatus;
224
- } | {
225
- isLoading: boolean;
226
- isFetching: boolean;
227
- isRefetching: boolean;
228
- isFetched: boolean;
229
- isPlaceholderData: boolean;
230
- items: any;
231
- pages: {};
232
- allItems: any;
233
- loading: boolean;
234
- loaded: boolean;
235
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
236
- updateItem: (item: any) => void;
237
- pagination: {
238
- page: number;
239
- lastPage: number;
240
- total: number;
241
- };
242
- error: null;
243
- isError: false;
244
- isPending: true;
245
- isLoadingError: false;
246
- isRefetchError: false;
247
- isSuccess: false;
248
- status: "pending";
249
- dataUpdatedAt: number;
250
- errorUpdatedAt: number;
251
- failureCount: number;
252
- failureReason: Error;
253
- errorUpdateCount: number;
254
- isFetchedAfterMount: boolean;
255
- isInitialLoading: boolean;
256
- isPaused: boolean;
257
- isStale: boolean;
258
- isEnabled: boolean;
259
- fetchStatus: _tanstack_react_query.FetchStatus;
260
- } | {
261
- isLoading: boolean;
262
- isFetching: boolean;
263
- isRefetching: boolean;
264
- isFetched: boolean;
265
- isPlaceholderData: boolean;
266
- items: any;
267
- pages: {};
268
- allItems: any;
269
- loading: boolean;
270
- loaded: boolean;
271
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
272
- updateItem: (item: any) => void;
273
- pagination: {
274
- page: number;
275
- lastPage: number;
276
- total: number;
277
- };
278
- isError: false;
279
- error: null;
280
- isPending: false;
281
- isLoadingError: false;
282
- isRefetchError: false;
283
- isSuccess: true;
284
- status: "success";
285
- dataUpdatedAt: number;
286
- errorUpdatedAt: number;
287
- failureCount: number;
288
- failureReason: Error;
289
- errorUpdateCount: number;
290
- isFetchedAfterMount: boolean;
291
- isInitialLoading: boolean;
292
- isPaused: boolean;
293
- isStale: boolean;
294
- isEnabled: boolean;
295
- fetchStatus: _tanstack_react_query.FetchStatus;
296
- };
297
-
298
- type MutationOptions$2 = UseMutationOptions<unknown, Error, string | void>;
299
- declare function useResourceDestroy(resource: Resource | string): any;
300
- declare function useResourceDestroy(id: string | null): any;
301
- declare function useResourceDestroy(resource: Resource | string, id: string | null): any;
302
- declare function useResourceDestroy(resource: Resource | string, options: MutationOptions$2): any;
303
- declare function useResourceDestroy(id: string | null, options: MutationOptions$2): any;
304
- declare function useResourceDestroy(resource: Resource | string, id: string | null, options: MutationOptions$2): any;
305
-
306
- declare function useResourceItem(id: string | null): any;
307
- declare function useResourceItem(id: string | null, opts: any): any;
308
- declare function useResourceItem(resource: Resource | string | null, id: string | null): any;
309
- declare function useResourceItem(resource: Resource | string | null, id: string | null, opts: any): any;
310
-
311
- declare function useResourceItems(): any;
312
- declare function useResourceItems(resource: Resource | string): any;
313
- declare function useResourceItems(resource: Resource | string, query: Record<string, unknown> | null): any;
314
- declare function useResourceItems(resource: Resource | string, query: Record<string, unknown> | null, page: number | null): any;
315
- declare function useResourceItems(resource: Resource | string, query: Record<string, unknown> | null, page: number | null, count: number | null): any;
316
- declare function useResourceItems<T = ResourceItem>(resource: Resource | string, query: Record<string, unknown> | null, page: number | null, count: number | null, opts: UseItemsOptions<T>): any;
317
- declare function useResourceItems(query: Record<string, unknown> | null): any;
318
- declare function useResourceItems(query: Record<string, unknown> | null, page: number | null): any;
319
- declare function useResourceItems(query: Record<string, unknown> | null, page: number | null, count: number | null): any;
320
- declare function useResourceItems<T = ResourceItem>(query: Record<string, unknown> | null, page: number | null, count: number | null, opts: UseItemsOptions<T>): any;
321
-
322
- declare function useResourceStore(resource: Resource | string, options: any): any;
323
- declare function useResourceStore(options: any): any;
324
-
325
- declare function useResourceUpdate(resource: Resource | string, id: string): any;
326
- declare function useResourceUpdate(resource: Resource | string, id: string, options: UseMutationOptions): any;
327
- declare function useResourceUpdate(id: string): any;
328
- declare function useResourceUpdate(id: string, options: UseMutationOptions): any;
329
-
330
- type MutationOptions$1 = UseMutationOptions<unknown, Error, string | void>;
331
- declare function useResourceClone(resource: Resource | string): any;
332
- declare function useResourceClone(id: string | null): any;
333
- declare function useResourceClone(resource: Resource | string, id: string | null): any;
334
- declare function useResourceClone(resource: Resource | string, options: MutationOptions$1): any;
335
- declare function useResourceClone(id: string | null, options: MutationOptions$1): any;
336
- declare function useResourceClone(resource: Resource | string, id: string | null, options: MutationOptions$1): any;
337
-
338
- type MutationOptions = UseMutationOptions<unknown, Error, string | void>;
339
- declare function useResourceRestore(resource: Resource | string): any;
340
- declare function useResourceRestore(id: string | null): any;
341
- declare function useResourceRestore(resource: Resource | string, id: string | null): any;
342
- declare function useResourceRestore(resource: Resource | string, options: MutationOptions): any;
343
- declare function useResourceRestore(id: string | null, options: MutationOptions): any;
344
- declare function useResourceRestore(resource: Resource | string, id: string | null, options: MutationOptions): any;
345
-
346
- interface ApiOptions {
347
- baseUrl?: string | null;
348
- routes?: Record<string, string>;
349
- generateUrl?: ((routeName: string, params?: Record<string, unknown>) => string | null) | null;
350
- onUnauthorized?: (() => void) | null;
351
- }
352
- declare class Base {
353
- options: ApiOptions;
354
- constructor(opts: ApiOptions);
355
- requestGet<T = unknown>(path: string, query?: Record<string, unknown> | null, opts?: Record<string, unknown> | null): Promise<T | null>;
356
- requestPost<T = unknown>(path: string, data?: Record<string, unknown> | null, opts?: Record<string, unknown> | null): Promise<T | null>;
357
- requestPut<T = unknown>(path: string, data: Record<string, unknown>, opts?: Record<string, unknown> | null): Promise<T>;
358
- requestPatch<T = unknown>(path: string, data: Record<string, unknown>, opts?: Record<string, unknown> | null): Promise<T | null>;
359
- requestDelete<T = unknown>(path: string, opts?: Record<string, unknown> | null): Promise<T | null>;
360
- hasRoute(route: string): boolean;
361
- route(route: string, params?: Record<string, unknown> | null): string | null;
362
- getFullUrl(path: string | null, query?: Record<string, unknown> | null): string;
363
- onError(err: any): void;
364
- }
365
-
366
- declare class AccountApi extends Base {
367
- constructor(opts: any);
368
- update(data: any): Promise<unknown>;
369
- updatePassword(data: any): Promise<unknown>;
370
- delete(data: any): Promise<unknown>;
371
- }
372
-
373
- declare class AuthApi extends Base {
374
- constructor(opts: any);
375
- check(): Promise<unknown>;
376
- login(email: any, password: any): Promise<unknown>;
377
- register(data: any): Promise<unknown>;
378
- logout(): Promise<unknown>;
379
- requestPassword(email: any): Promise<unknown>;
380
- resetPassword(data: any): Promise<unknown>;
381
- }
382
-
383
- declare class MediasApi extends Base {
384
- constructor(opts: any);
385
- find(id: string): Promise<Media>;
386
- get(query?: Record<string, unknown>, page?: number | null, count?: number | null): Promise<UseItemsResponse<Media>>;
387
- getTrashed(query?: Record<string, unknown>, page?: number | null, count?: number | null): Promise<UseItemsResponse<Media>>;
388
- getTags(query?: Record<string, unknown>, count?: number | null): Promise<unknown>;
389
- create(data: Record<string, unknown>): Promise<Media>;
390
- update(id: string, data: Record<string, unknown>): Promise<Media>;
391
- trash(id: string): Promise<unknown>;
392
- restore(id: string): Promise<Media>;
393
- destroy(id: string): Promise<unknown>;
394
- replace(id: string, data: Record<string, unknown>): Promise<Media>;
395
- }
396
-
397
- type ItemsResponse<T> = {
398
- data: T[];
399
- pagination: Pagination;
400
- meta?: Pagination;
401
- } | T[];
402
- declare class ResourcesApi extends Base {
403
- constructor(opts: any);
404
- find<T = ResourceItem>(resource: Resource, id: string, opts?: Record<string, unknown> | null): Promise<T>;
405
- get<T = ResourceItem, TResponse = ItemsResponse<T>>(resource: Resource, query: Record<string, unknown>, page?: number, count?: number, opts?: Record<string, unknown> | null): Promise<TResponse>;
406
- store<T = ResourceItem>(resource: Resource, data: Record<string, unknown>, opts?: Record<string, unknown> | null): Promise<T>;
407
- update<T = ResourceItem>(resource: Resource, id: string, data: Record<string, unknown>, opts?: Record<string, unknown> | null): Promise<T>;
408
- destroy<T = unknown>(resource: Resource, id: string, opts?: Record<string, unknown> | null): Promise<T>;
409
- clone<T = ResourceItem>(resource: Resource, id: string, data?: Record<string, unknown> | null, opts?: Record<string, unknown> | null): Promise<T>;
410
- restore<T = ResourceItem>(resource: Resource, id: string, data?: Record<string, unknown> | null, opts?: Record<string, unknown> | null): Promise<T>;
411
- resourceRoute({ id }: Resource, route: string, params?: Record<string, unknown> | null): string | null;
412
- }
413
-
414
- declare class Api extends Base {
415
- resources: ResourcesApi;
416
- medias: MediasApi;
417
- auth: AuthApi;
418
- account: AccountApi;
419
- constructor(opts: any);
420
- }
421
-
422
- declare function useApi(): Api;
423
- interface ApiProviderProps {
424
- api?: Api | null;
425
- baseUrl?: string;
426
- onUnauthorized?: (() => void) | null;
427
- routes?: Record<string, string> | null;
428
- children: ReactNode;
429
- }
430
- declare function ApiProvider({ api: initialApi, baseUrl, onUnauthorized, routes: apiRoutes, children, }: ApiProviderProps): react.JSX.Element;
431
-
432
- type QueryInitialData = Record<string, unknown> | Array<Record<string, unknown>>;
433
- interface QueryProviderProps {
434
- config?: QueryClientConfig | null;
435
- initialKey?: string[] | null;
436
- initialData?: QueryInitialData | null;
437
- children: ReactNode;
438
- }
439
- declare function useQueryContext(): QueryClient;
440
- declare function QueryProvider({ config: initialConfig, initialKey, initialData, children, }: QueryProviderProps): react.JSX.Element;
441
-
442
- interface DataProviderProps {
443
- api?: Api | null;
444
- apiBaseUrl?: string;
445
- routes?: Record<string, string> | null;
446
- baseUrl?: string;
447
- queryConfig?: QueryClientConfig | null;
448
- initialQueryKey?: string[] | null;
449
- initialQueryData?: Record<string, unknown> | Array<Record<string, unknown>> | null;
450
- onUnauthorized?: (() => void) | null;
451
- children?: ReactNode;
452
- }
453
- declare function DataProvider({ api, apiBaseUrl, routes, baseUrl, children, queryConfig, initialQueryKey, initialQueryData, onUnauthorized, }: DataProviderProps): react.JSX.Element;
454
-
455
- export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceStore, useResourceUpdate };
456
- export type { UseItemsResponse };
1
+ export type { ActionResponse, DataAdapter, LoginCredentials, MediaQuery, RequestOptions, UpdateOptions, Values, } from './adapter';
2
+ export { ApiError, ConflictError, ForbiddenError, InvalidResponseError, NotFoundError, UnauthorizedError, ValidationError, createApiError, isApiError, } from './errors';
3
+ export { type RestAdapterOptions, createRestAdapter } from './rest';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,aAAa,EACb,MAAM,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EACH,QAAQ,EACR,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,UAAU,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC"}