@objectstack/client-react 1.0.2 → 1.0.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.
@@ -0,0 +1,22 @@
1
+
2
+ > @objectstack/client-react@1.0.5 build /home/runner/work/spec/spec/packages/client-react
3
+ > tsup src/index.tsx --config ../../tsup.config.ts
4
+
5
+ CLI Building entry: src/index.tsx
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/spec/spec/tsup.config.ts
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.mjs 12.47 KB
14
+ ESM dist/index.mjs.map 35.40 KB
15
+ ESM ⚡️ Build success in 49ms
16
+ CJS dist/index.js 15.27 KB
17
+ CJS dist/index.js.map 35.43 KB
18
+ CJS ⚡️ Build success in 49ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 10112ms
21
+ DTS dist/index.d.mts 11.92 KB
22
+ DTS dist/index.d.ts 11.92 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @objectstack/client-react
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - b1d24bd: refactor: migrate build system from tsc to tsup for faster builds
8
+ - Replaced `tsc` with `tsup` (using esbuild) across all packages
9
+ - Added shared `tsup.config.ts` in workspace root
10
+ - Added `tsup` as workspace dev dependency
11
+ - significantly improved build performance
12
+ - 877b864: fix: add SPA fallback to hono, fix msw context binding, improve runtime resilience, and fix client-react build types
13
+ - Updated dependencies [b1d24bd]
14
+ - @objectstack/core@1.0.5
15
+ - @objectstack/client@1.0.5
16
+ - @objectstack/spec@1.0.5
17
+
18
+ ## 1.0.4
19
+
20
+ ### Patch Changes
21
+
22
+ - @objectstack/spec@1.0.4
23
+ - @objectstack/core@1.0.4
24
+ - @objectstack/client@1.0.4
25
+
26
+ ## 1.0.3
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [fb2eabd]
31
+ - @objectstack/core@1.0.3
32
+ - @objectstack/client@1.0.3
33
+ - @objectstack/spec@1.0.3
34
+
3
35
  ## 1.0.2
4
36
 
5
37
  ### Patch Changes
@@ -0,0 +1,416 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { ObjectStackClient, PaginatedResult } from '@objectstack/client';
4
+ export { ClientConfig, ObjectStackClient } from '@objectstack/client';
5
+ import { QueryAST, FilterCondition } from '@objectstack/spec/data';
6
+
7
+ /**
8
+ * ObjectStack React Context
9
+ *
10
+ * Provides ObjectStackClient instance to React components via Context API
11
+ */
12
+
13
+ interface ObjectStackProviderProps {
14
+ client: ObjectStackClient;
15
+ children: ReactNode;
16
+ }
17
+ declare const ObjectStackContext: React.Context<ObjectStackClient | null>;
18
+ /**
19
+ * Provider component that makes ObjectStackClient available to all child components
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' });
24
+ *
25
+ * function App() {
26
+ * return (
27
+ * <ObjectStackProvider client={client}>
28
+ * <YourComponents />
29
+ * </ObjectStackProvider>
30
+ * );
31
+ * }
32
+ * ```
33
+ */
34
+ declare function ObjectStackProvider({ client, children }: ObjectStackProviderProps): React.JSX.Element;
35
+ /**
36
+ * Hook to access the ObjectStackClient instance from context
37
+ *
38
+ * @throws Error if used outside of ObjectStackProvider
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * function MyComponent() {
43
+ * const client = useClient();
44
+ * // Use client.data.find(), etc.
45
+ * }
46
+ * ```
47
+ */
48
+ declare function useClient(): ObjectStackClient;
49
+
50
+ /**
51
+ * Data Query Hooks
52
+ *
53
+ * React hooks for querying and mutating ObjectStack data
54
+ */
55
+
56
+ /**
57
+ * Query options for useQuery hook
58
+ */
59
+ interface UseQueryOptions<T = any> {
60
+ /** Query AST or simplified query options */
61
+ query?: Partial<QueryAST>;
62
+ /** Simple field selection */
63
+ select?: string[];
64
+ /** Simple filters */
65
+ filters?: FilterCondition;
66
+ /** Sort configuration */
67
+ sort?: string | string[];
68
+ /** Limit results */
69
+ top?: number;
70
+ /** Skip results (for pagination) */
71
+ skip?: number;
72
+ /** Enable/disable automatic query execution */
73
+ enabled?: boolean;
74
+ /** Refetch interval in milliseconds */
75
+ refetchInterval?: number;
76
+ /** Callback on successful query */
77
+ onSuccess?: (data: PaginatedResult<T>) => void;
78
+ /** Callback on error */
79
+ onError?: (error: Error) => void;
80
+ }
81
+ /**
82
+ * Query result for useQuery hook
83
+ */
84
+ interface UseQueryResult<T = any> {
85
+ /** Query result data */
86
+ data: PaginatedResult<T> | null;
87
+ /** Loading state */
88
+ isLoading: boolean;
89
+ /** Error state */
90
+ error: Error | null;
91
+ /** Refetch the query */
92
+ refetch: () => Promise<void>;
93
+ /** Is currently refetching */
94
+ isRefetching: boolean;
95
+ }
96
+ /**
97
+ * Hook for querying ObjectStack data with automatic caching and refetching
98
+ *
99
+ * @example
100
+ * ```tsx
101
+ * function TaskList() {
102
+ * const { data, isLoading, error, refetch } = useQuery('todo_task', {
103
+ * select: ['id', 'subject', 'priority'],
104
+ * sort: ['-created_at'],
105
+ * top: 20
106
+ * });
107
+ *
108
+ * if (isLoading) return <div>Loading...</div>;
109
+ * if (error) return <div>Error: {error.message}</div>;
110
+ *
111
+ * return (
112
+ * <div>
113
+ * {data?.value.map(task => (
114
+ * <div key={task.id}>{task.subject}</div>
115
+ * ))}
116
+ * </div>
117
+ * );
118
+ * }
119
+ * ```
120
+ */
121
+ declare function useQuery<T = any>(object: string, options?: UseQueryOptions<T>): UseQueryResult<T>;
122
+ /**
123
+ * Mutation options for useMutation hook
124
+ */
125
+ interface UseMutationOptions<TData = any, TVariables = any> {
126
+ /** Callback on successful mutation */
127
+ onSuccess?: (data: TData, variables: TVariables) => void;
128
+ /** Callback on error */
129
+ onError?: (error: Error, variables: TVariables) => void;
130
+ /** Callback when mutation is settled (success or error) */
131
+ onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables) => void;
132
+ }
133
+ /**
134
+ * Mutation result for useMutation hook
135
+ */
136
+ interface UseMutationResult<TData = any, TVariables = any> {
137
+ /** Execute the mutation */
138
+ mutate: (variables: TVariables) => Promise<TData>;
139
+ /** Async version of mutate that throws errors */
140
+ mutateAsync: (variables: TVariables) => Promise<TData>;
141
+ /** Mutation result data */
142
+ data: TData | null;
143
+ /** Loading state */
144
+ isLoading: boolean;
145
+ /** Error state */
146
+ error: Error | null;
147
+ /** Reset mutation state */
148
+ reset: () => void;
149
+ }
150
+ /**
151
+ * Hook for creating, updating, or deleting ObjectStack data
152
+ *
153
+ * @example
154
+ * ```tsx
155
+ * function CreateTaskForm() {
156
+ * const { mutate, isLoading, error } = useMutation('todo_task', 'create', {
157
+ * onSuccess: (data) => {
158
+ * console.log('Task created:', data);
159
+ * }
160
+ * });
161
+ *
162
+ * const handleSubmit = (formData) => {
163
+ * mutate(formData);
164
+ * };
165
+ *
166
+ * return <form onSubmit={handleSubmit}>...</form>;
167
+ * }
168
+ * ```
169
+ */
170
+ declare function useMutation<TData = any, TVariables = any>(object: string, operation: 'create' | 'update' | 'delete' | 'createMany' | 'updateMany' | 'deleteMany', options?: UseMutationOptions<TData, TVariables>): UseMutationResult<TData, TVariables>;
171
+ /**
172
+ * Pagination options for usePagination hook
173
+ */
174
+ interface UsePaginationOptions<T = any> extends Omit<UseQueryOptions<T>, 'top' | 'skip'> {
175
+ /** Page size */
176
+ pageSize?: number;
177
+ /** Initial page (1-based) */
178
+ initialPage?: number;
179
+ }
180
+ /**
181
+ * Pagination result for usePagination hook
182
+ */
183
+ interface UsePaginationResult<T = any> extends UseQueryResult<T> {
184
+ /** Current page (1-based) */
185
+ page: number;
186
+ /** Total number of pages */
187
+ totalPages: number;
188
+ /** Total number of records */
189
+ totalCount: number;
190
+ /** Go to next page */
191
+ nextPage: () => void;
192
+ /** Go to previous page */
193
+ previousPage: () => void;
194
+ /** Go to specific page */
195
+ goToPage: (page: number) => void;
196
+ /** Whether there is a next page */
197
+ hasNextPage: boolean;
198
+ /** Whether there is a previous page */
199
+ hasPreviousPage: boolean;
200
+ }
201
+ /**
202
+ * Hook for paginated data queries
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * function PaginatedTaskList() {
207
+ * const {
208
+ * data,
209
+ * isLoading,
210
+ * page,
211
+ * totalPages,
212
+ * nextPage,
213
+ * previousPage,
214
+ * hasNextPage,
215
+ * hasPreviousPage
216
+ * } = usePagination('todo_task', {
217
+ * pageSize: 10,
218
+ * sort: ['-created_at']
219
+ * });
220
+ *
221
+ * return (
222
+ * <div>
223
+ * {data?.value.map(task => <div key={task.id}>{task.subject}</div>)}
224
+ * <button onClick={previousPage} disabled={!hasPreviousPage}>Previous</button>
225
+ * <span>Page {page} of {totalPages}</span>
226
+ * <button onClick={nextPage} disabled={!hasNextPage}>Next</button>
227
+ * </div>
228
+ * );
229
+ * }
230
+ * ```
231
+ */
232
+ declare function usePagination<T = any>(object: string, options?: UsePaginationOptions<T>): UsePaginationResult<T>;
233
+ /**
234
+ * Infinite query options for useInfiniteQuery hook
235
+ */
236
+ interface UseInfiniteQueryOptions<T = any> extends Omit<UseQueryOptions<T>, 'skip'> {
237
+ /** Page size for each fetch */
238
+ pageSize?: number;
239
+ /** Get next page parameter */
240
+ getNextPageParam?: (lastPage: PaginatedResult<T>, allPages: PaginatedResult<T>[]) => number | undefined;
241
+ }
242
+ /**
243
+ * Infinite query result for useInfiniteQuery hook
244
+ */
245
+ interface UseInfiniteQueryResult<T = any> {
246
+ /** All pages of data */
247
+ data: PaginatedResult<T>[];
248
+ /** Flattened data from all pages */
249
+ flatData: T[];
250
+ /** Loading state */
251
+ isLoading: boolean;
252
+ /** Error state */
253
+ error: Error | null;
254
+ /** Load the next page */
255
+ fetchNextPage: () => Promise<void>;
256
+ /** Whether there are more pages */
257
+ hasNextPage: boolean;
258
+ /** Is currently fetching next page */
259
+ isFetchingNextPage: boolean;
260
+ /** Refetch all pages */
261
+ refetch: () => Promise<void>;
262
+ }
263
+ /**
264
+ * Hook for infinite scrolling / load more functionality
265
+ *
266
+ * @example
267
+ * ```tsx
268
+ * function InfiniteTaskList() {
269
+ * const {
270
+ * flatData,
271
+ * isLoading,
272
+ * fetchNextPage,
273
+ * hasNextPage,
274
+ * isFetchingNextPage
275
+ * } = useInfiniteQuery('todo_task', {
276
+ * pageSize: 20,
277
+ * sort: ['-created_at']
278
+ * });
279
+ *
280
+ * return (
281
+ * <div>
282
+ * {flatData.map(task => <div key={task.id}>{task.subject}</div>)}
283
+ * {hasNextPage && (
284
+ * <button onClick={fetchNextPage} disabled={isFetchingNextPage}>
285
+ * {isFetchingNextPage ? 'Loading...' : 'Load More'}
286
+ * </button>
287
+ * )}
288
+ * </div>
289
+ * );
290
+ * }
291
+ * ```
292
+ */
293
+ declare function useInfiniteQuery<T = any>(object: string, options?: UseInfiniteQueryOptions<T>): UseInfiniteQueryResult<T>;
294
+
295
+ /**
296
+ * Metadata Hooks
297
+ *
298
+ * React hooks for accessing ObjectStack metadata (schemas, views, fields)
299
+ */
300
+
301
+ /**
302
+ * Metadata query options
303
+ */
304
+ interface UseMetadataOptions {
305
+ /** Enable/disable automatic query execution */
306
+ enabled?: boolean;
307
+ /** Use cached metadata if available */
308
+ useCache?: boolean;
309
+ /** ETag for conditional requests */
310
+ ifNoneMatch?: string;
311
+ /** If-Modified-Since header for conditional requests */
312
+ ifModifiedSince?: string;
313
+ /** Callback on successful query */
314
+ onSuccess?: (data: any) => void;
315
+ /** Callback on error */
316
+ onError?: (error: Error) => void;
317
+ }
318
+ /**
319
+ * Metadata query result
320
+ */
321
+ interface UseMetadataResult<T = any> {
322
+ /** Metadata data */
323
+ data: T | null;
324
+ /** Loading state */
325
+ isLoading: boolean;
326
+ /** Error state */
327
+ error: Error | null;
328
+ /** Refetch the metadata */
329
+ refetch: () => Promise<void>;
330
+ /** ETag from last fetch */
331
+ etag?: string;
332
+ /** Whether data came from cache (304 Not Modified) */
333
+ fromCache: boolean;
334
+ }
335
+ /**
336
+ * Hook for fetching object schema/metadata
337
+ *
338
+ * @example
339
+ * ```tsx
340
+ * function ObjectSchemaViewer({ objectName }: { objectName: string }) {
341
+ * const { data: schema, isLoading, error } = useObject(objectName);
342
+ *
343
+ * if (isLoading) return <div>Loading schema...</div>;
344
+ * if (error) return <div>Error: {error.message}</div>;
345
+ *
346
+ * return (
347
+ * <div>
348
+ * <h2>{schema.label}</h2>
349
+ * <p>Fields: {Object.keys(schema.fields).length}</p>
350
+ * </div>
351
+ * );
352
+ * }
353
+ * ```
354
+ */
355
+ declare function useObject(objectName: string, options?: UseMetadataOptions): UseMetadataResult;
356
+ /**
357
+ * Hook for fetching view configuration
358
+ *
359
+ * @example
360
+ * ```tsx
361
+ * function ViewConfiguration({ objectName }: { objectName: string }) {
362
+ * const { data: view, isLoading } = useView(objectName, 'list');
363
+ *
364
+ * if (isLoading) return <div>Loading view...</div>;
365
+ *
366
+ * return (
367
+ * <div>
368
+ * <h3>List View for {objectName}</h3>
369
+ * <p>Columns: {view?.columns?.length}</p>
370
+ * </div>
371
+ * );
372
+ * }
373
+ * ```
374
+ */
375
+ declare function useView(objectName: string, viewType?: 'list' | 'form', options?: UseMetadataOptions): UseMetadataResult;
376
+ /**
377
+ * Hook for extracting fields from object schema
378
+ *
379
+ * @example
380
+ * ```tsx
381
+ * function FieldList({ objectName }: { objectName: string }) {
382
+ * const { data: fields, isLoading } = useFields(objectName);
383
+ *
384
+ * if (isLoading) return <div>Loading fields...</div>;
385
+ *
386
+ * return (
387
+ * <ul>
388
+ * {fields?.map(field => (
389
+ * <li key={field.name}>{field.label} ({field.type})</li>
390
+ * ))}
391
+ * </ul>
392
+ * );
393
+ * }
394
+ * ```
395
+ */
396
+ declare function useFields(objectName: string, options?: UseMetadataOptions): UseMetadataResult<any[]>;
397
+ /**
398
+ * Generic metadata hook for custom metadata queries
399
+ *
400
+ * @example
401
+ * ```tsx
402
+ * function CustomMetadata() {
403
+ * const { data, isLoading } = useMetadata(async (client) => {
404
+ * // Custom metadata fetching logic
405
+ * const object = await client.meta.getObject('custom_object');
406
+ * const view = await client.meta.getView('custom_object', 'list');
407
+ * return { object, view };
408
+ * });
409
+ *
410
+ * return <pre>{JSON.stringify(data, null, 2)}</pre>;
411
+ * }
412
+ * ```
413
+ */
414
+ declare function useMetadata<T = any>(fetcher: (client: ReturnType<typeof useClient>) => Promise<T>, options?: Omit<UseMetadataOptions, 'useCache' | 'ifNoneMatch' | 'ifModifiedSince'>): UseMetadataResult<T>;
415
+
416
+ export { ObjectStackContext, ObjectStackProvider, type ObjectStackProviderProps, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMetadataOptions, type UseMetadataResult, type UseMutationOptions, type UseMutationResult, type UsePaginationOptions, type UsePaginationResult, type UseQueryOptions, type UseQueryResult, useClient, useFields, useInfiniteQuery, useMetadata, useMutation, useObject, usePagination, useQuery, useView };