next-data-kit 4.0.0 → 6.0.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 (77) hide show
  1. package/README.md +40 -8
  2. package/dist/{next-data-kit-DgLsBFv3.d.cts → action-DwiE6Cov.d.cts} +44 -5
  3. package/dist/{next-data-kit-DgLsBFv3.d.ts → action-DwiE6Cov.d.ts} +44 -5
  4. package/dist/client/components/data-kit-table.d.ts +3 -3
  5. package/dist/client/components/data-kit-table.d.ts.map +1 -1
  6. package/dist/client/components/data-kit-table.js.map +1 -1
  7. package/dist/client/components/data-kit.d.ts.map +1 -1
  8. package/dist/client/components/data-kit.js.map +1 -1
  9. package/dist/client/hooks/index.d.ts +1 -1
  10. package/dist/client/hooks/index.d.ts.map +1 -1
  11. package/dist/client/hooks/index.js.map +1 -1
  12. package/dist/client/hooks/useDataKit.d.ts +3 -3
  13. package/dist/client/hooks/useDataKit.d.ts.map +1 -1
  14. package/dist/client/hooks/useDataKit.js.map +1 -1
  15. package/dist/client/hooks/usePagination.d.ts.map +1 -1
  16. package/dist/client/hooks/usePagination.js +1 -1
  17. package/dist/client/hooks/usePagination.js.map +1 -1
  18. package/dist/client/index.d.ts +4 -4
  19. package/dist/client/index.d.ts.map +1 -1
  20. package/dist/client/index.js +3 -3
  21. package/dist/client/index.js.map +1 -1
  22. package/dist/index.cjs +47 -49
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +53 -47
  25. package/dist/index.d.ts +53 -47
  26. package/dist/index.js +47 -49
  27. package/dist/index.js.map +1 -1
  28. package/dist/server/utils.d.ts +52 -0
  29. package/dist/server/utils.d.ts.map +1 -0
  30. package/dist/server/utils.js +117 -0
  31. package/dist/server/utils.js.map +1 -0
  32. package/dist/server.cjs +48 -39
  33. package/dist/server.cjs.map +1 -1
  34. package/dist/server.d.cts +10 -38
  35. package/dist/server.d.ts +10 -38
  36. package/dist/server.js +48 -40
  37. package/dist/server.js.map +1 -1
  38. package/dist/types/{component.d.ts → client/component.d.ts} +5 -5
  39. package/dist/types/client/component.d.ts.map +1 -0
  40. package/dist/types/client/component.js.map +1 -0
  41. package/dist/types/{hook.d.ts → client/hook.d.ts} +3 -3
  42. package/dist/types/client/hook.d.ts.map +1 -0
  43. package/dist/types/client/hook.js.map +1 -0
  44. package/dist/types/client/selectable.d.ts.map +1 -0
  45. package/dist/types/client/selectable.js.map +1 -0
  46. package/dist/types/index.cjs +0 -11
  47. package/dist/types/index.cjs.map +1 -1
  48. package/dist/types/index.d.cts +10 -9
  49. package/dist/types/index.d.ts +5 -5
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/dist/types/index.js +1 -1
  52. package/dist/types/index.js.map +1 -1
  53. package/dist/types/next-data-kit.d.ts +1 -5
  54. package/dist/types/next-data-kit.d.ts.map +1 -1
  55. package/dist/types/next-data-kit.js +1 -11
  56. package/dist/types/next-data-kit.js.map +1 -1
  57. package/dist/types/server/action.d.ts +43 -0
  58. package/dist/types/server/action.d.ts.map +1 -0
  59. package/dist/types/server/action.js +7 -0
  60. package/dist/types/server/action.js.map +1 -0
  61. package/dist/types/server/database/mongo.d.ts.map +1 -0
  62. package/dist/types/server/database/mongo.js.map +1 -0
  63. package/package.json +1 -1
  64. package/dist/types/component.d.ts.map +0 -1
  65. package/dist/types/component.js.map +0 -1
  66. package/dist/types/database/mongo.d.ts.map +0 -1
  67. package/dist/types/database/mongo.js.map +0 -1
  68. package/dist/types/hook.d.ts.map +0 -1
  69. package/dist/types/hook.js.map +0 -1
  70. package/dist/types/selectable.d.ts.map +0 -1
  71. package/dist/types/selectable.js.map +0 -1
  72. /package/dist/types/{component.js → client/component.js} +0 -0
  73. /package/dist/types/{hook.js → client/hook.js} +0 -0
  74. /package/dist/types/{selectable.d.ts → client/selectable.d.ts} +0 -0
  75. /package/dist/types/{selectable.js → client/selectable.js} +0 -0
  76. /package/dist/types/{database → server/database}/mongo.d.ts +0 -0
  77. /package/dist/types/{database → server/database}/mongo.js +0 -0
package/dist/index.d.cts CHANGED
@@ -125,10 +125,6 @@ type TPaginationInfo = {
125
125
  hasNextPage: boolean;
126
126
  hasPrevPage: boolean;
127
127
  };
128
- /**
129
- * Calculate pagination info from next-data-kit result
130
- */
131
- declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
132
128
  /**
133
129
  * React Data Kit Adapter Interface
134
130
  * Defines the contract for a database adapter.
@@ -145,6 +141,47 @@ type TDataKitAdapter<T> = (params: Readonly<{
145
141
  total: number;
146
142
  }>;
147
143
 
144
+ /**
145
+ * next-data-kit - Server Action Types
146
+ *
147
+ * Types for the server action and data kit operations.
148
+ */
149
+
150
+ /**
151
+ * Extract document type from a Mongoose Model.
152
+ */
153
+ type TExtractDocType<M> = M extends Model<infer TRawDocType, any, any, any, any, any> ? TRawDocType : never;
154
+ /**
155
+ * Base options shared by both mongoose and adapter versions
156
+ */
157
+ type TBaseOptions<TDoc, R> = {
158
+ input: TDataKitInput<TDoc>;
159
+ item: (item: TDoc) => Promise<R> | R;
160
+ filterAllowed?: string[];
161
+ maxLimit?: number;
162
+ queryAllowed?: (keyof TDoc | string)[];
163
+ };
164
+ /**
165
+ * Options when using a Mongoose model
166
+ */
167
+ type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
168
+ model: M;
169
+ adapter?: never;
170
+ filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
171
+ filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
172
+ defaultSort?: TSortOptions<TDoc>;
173
+ };
174
+ /**
175
+ * Options when using a custom adapter
176
+ */
177
+ type TAdapterOptions<TDoc, R> = TBaseOptions<TDoc, R> & {
178
+ adapter: TDataKitAdapter<TDoc>;
179
+ model?: never;
180
+ filter?: never;
181
+ filterCustom?: TFilterCustomConfigWithFilter<TDoc, unknown>;
182
+ defaultSort?: never;
183
+ };
184
+
148
185
  /**
149
186
  * next-data-kit - Hook Types
150
187
  *
@@ -206,9 +243,9 @@ type TUseDataKitReturn<T = unknown, R = unknown> = {
206
243
  actions: TDataKitActions<T, R>;
207
244
  };
208
245
  /**
209
- * React Data Kit controller options
246
+ * Options for the useDataKit hook
210
247
  */
211
- type TDataKitControllerOptions<T = unknown, R = unknown> = {
248
+ type TUseDataKitOptions<T = unknown, R = unknown> = {
212
249
  initial?: {
213
250
  page?: number;
214
251
  limit?: number;
@@ -299,9 +336,9 @@ type TSelectable = {
299
336
  */
300
337
  type TExtractDataKitItemFromResult<R> = R extends TDataKitResult<infer I> ? I : R extends {
301
338
  items: (infer I)[];
302
- } ? I : R extends [true, infer Ok] ? Ok extends {
339
+ } ? I : R extends [true, infer Ok] ? (Ok extends {
303
340
  items: (infer I)[];
304
- } ? I : never : never;
341
+ } ? I : never) : never;
305
342
  /**
306
343
  * Extract the item type from an action function's return type
307
344
  */
@@ -373,9 +410,9 @@ type TDataKitBulkAction<TItem> = {
373
410
  } | string]>;
374
411
  };
375
412
  /**
376
- * Controller for external table manipulation
413
+ * Controller ref for external DataKitTable manipulation
377
414
  */
378
- type TDataKitComponentController<TItem> = {
415
+ type TDataKitController<TItem> = {
379
416
  itemPush: (item: TItem, position?: 0 | 1) => void;
380
417
  refetchData: () => void;
381
418
  deleteBulk: (items: TItem[]) => void;
@@ -405,40 +442,6 @@ type TDataKitRef<T = unknown, R = unknown> = TUseDataKitReturn<T, R>;
405
442
  * with pagination, filtering, and sorting.
406
443
  */
407
444
 
408
- /**
409
- * Extract document type from a Mongoose Model.
410
- */
411
- type TExtractDocType<M> = M extends Model<infer TRawDocType, any, any, any, any, any> ? TRawDocType : never;
412
- /**
413
- * Base options shared by both mongoose and adapter versions
414
- */
415
- type TBaseOptions<TDoc, R> = {
416
- input: TDataKitInput<TDoc>;
417
- item: (item: TDoc) => Promise<R> | R;
418
- filterAllowed?: string[];
419
- maxLimit?: number;
420
- queryAllowed?: (keyof TDoc | string)[];
421
- };
422
- /**
423
- * Options when using a Mongoose model
424
- */
425
- type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
426
- model: M;
427
- adapter?: never;
428
- filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
429
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
430
- defaultSort?: TSortOptions<TDoc>;
431
- };
432
- /**
433
- * Options when using a custom adapter
434
- */
435
- type TAdapterOptions<TDoc, R> = TBaseOptions<TDoc, R> & {
436
- adapter: TDataKitAdapter<TDoc>;
437
- model?: never;
438
- filter?: never;
439
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, unknown>;
440
- defaultSort?: never;
441
- };
442
445
  /**
443
446
  * Server action with Mongoose model (auto-infers document type)
444
447
  */
@@ -458,7 +461,6 @@ declare const mongooseAdapter: <DocType = unknown>(model: TMongoModel<DocType>,
458
461
  filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<DocType>;
459
462
  filterCustom?: TFilterCustomConfigWithFilter<DocType, TMongoFilterQuery<DocType>>;
460
463
  defaultSort?: TSortOptions<DocType>;
461
- [key: string]: any;
462
464
  }>) => TDataKitAdapter<DocType>;
463
465
 
464
466
  /**
@@ -495,6 +497,10 @@ declare const escapeRegex: (str: string) => string;
495
497
  * ```
496
498
  */
497
499
  declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value: unknown) => TMongoFilterQuery<T>);
500
+ /**
501
+ * Calculate pagination info from page, limit, and total
502
+ */
503
+ declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
498
504
 
499
505
  /**
500
506
  * next-data-kit - useDataKit Hook
@@ -502,7 +508,7 @@ declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value:
502
508
  * React hook for managing next-data-kit state and actions.
503
509
  */
504
510
 
505
- declare const useDataKit: <T = unknown, R = unknown>(props: Readonly<TDataKitControllerOptions<T, R>>) => TUseDataKitReturn<T, R>;
511
+ declare const useDataKit: <T = unknown, R = unknown>(props: Readonly<TUseDataKitOptions<T, R>>) => TUseDataKitReturn<T, R>;
506
512
 
507
513
  /**
508
514
  * next-data-kit - useSelection Hook
@@ -608,4 +614,4 @@ declare const sortEntriesToKey: (sorts: TSortEntry[]) => string;
608
614
  */
609
615
  declare const keyToSortEntries: (key: string) => TSortEntry[];
610
616
 
611
- export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, type TDataKitActions, type TDataKitAdapter, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitComponentController, type TDataKitContextValue, type TDataKitControllerOptions, type TDataKitFilterItem, type TDataKitInput, type TDataKitRef, type TDataKitResult, type TDataKitSelectableItem, type TDataKitState, type TDataKitStateMode, type TExtractDataKitItemType, type TFilterConfig, type TFilterCustomConfig, type TFilterCustomConfigWithFilter, type TMongoFilterOperators, type TMongoFilterQuery, type TMongoModel, type TMongoRootFilterOperators, type TPaginationInfo, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, type TSortEntry, type TSortOptions, type TSortOrder, type TUseDataKitReturn, type TUsePaginationReturn, type TUseSelectionReturn, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
617
+ export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, type TAdapterOptions, type TBaseOptions, type TDataKitActions, type TDataKitAdapter, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitContextValue, type TDataKitController, type TDataKitFilterItem, type TDataKitInput, type TDataKitRef, type TDataKitResult, type TDataKitSelectableItem, type TDataKitState, type TDataKitStateMode, type TExtractDataKitItemType, type TExtractDocType, type TFilterConfig, type TFilterCustomConfig, type TFilterCustomConfigWithFilter, type TMongoFilterOperators, type TMongoFilterQuery, type TMongoModel, type TMongoRootFilterOperators, type TMongooseOptions, type TPaginationInfo, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, type TSortEntry, type TSortOptions, type TSortOrder, type TUseDataKitOptions, type TUseDataKitReturn, type TUsePaginationReturn, type TUseSelectionReturn, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
package/dist/index.d.ts CHANGED
@@ -125,10 +125,6 @@ type TPaginationInfo = {
125
125
  hasNextPage: boolean;
126
126
  hasPrevPage: boolean;
127
127
  };
128
- /**
129
- * Calculate pagination info from next-data-kit result
130
- */
131
- declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
132
128
  /**
133
129
  * React Data Kit Adapter Interface
134
130
  * Defines the contract for a database adapter.
@@ -145,6 +141,47 @@ type TDataKitAdapter<T> = (params: Readonly<{
145
141
  total: number;
146
142
  }>;
147
143
 
144
+ /**
145
+ * next-data-kit - Server Action Types
146
+ *
147
+ * Types for the server action and data kit operations.
148
+ */
149
+
150
+ /**
151
+ * Extract document type from a Mongoose Model.
152
+ */
153
+ type TExtractDocType<M> = M extends Model<infer TRawDocType, any, any, any, any, any> ? TRawDocType : never;
154
+ /**
155
+ * Base options shared by both mongoose and adapter versions
156
+ */
157
+ type TBaseOptions<TDoc, R> = {
158
+ input: TDataKitInput<TDoc>;
159
+ item: (item: TDoc) => Promise<R> | R;
160
+ filterAllowed?: string[];
161
+ maxLimit?: number;
162
+ queryAllowed?: (keyof TDoc | string)[];
163
+ };
164
+ /**
165
+ * Options when using a Mongoose model
166
+ */
167
+ type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
168
+ model: M;
169
+ adapter?: never;
170
+ filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
171
+ filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
172
+ defaultSort?: TSortOptions<TDoc>;
173
+ };
174
+ /**
175
+ * Options when using a custom adapter
176
+ */
177
+ type TAdapterOptions<TDoc, R> = TBaseOptions<TDoc, R> & {
178
+ adapter: TDataKitAdapter<TDoc>;
179
+ model?: never;
180
+ filter?: never;
181
+ filterCustom?: TFilterCustomConfigWithFilter<TDoc, unknown>;
182
+ defaultSort?: never;
183
+ };
184
+
148
185
  /**
149
186
  * next-data-kit - Hook Types
150
187
  *
@@ -206,9 +243,9 @@ type TUseDataKitReturn<T = unknown, R = unknown> = {
206
243
  actions: TDataKitActions<T, R>;
207
244
  };
208
245
  /**
209
- * React Data Kit controller options
246
+ * Options for the useDataKit hook
210
247
  */
211
- type TDataKitControllerOptions<T = unknown, R = unknown> = {
248
+ type TUseDataKitOptions<T = unknown, R = unknown> = {
212
249
  initial?: {
213
250
  page?: number;
214
251
  limit?: number;
@@ -299,9 +336,9 @@ type TSelectable = {
299
336
  */
300
337
  type TExtractDataKitItemFromResult<R> = R extends TDataKitResult<infer I> ? I : R extends {
301
338
  items: (infer I)[];
302
- } ? I : R extends [true, infer Ok] ? Ok extends {
339
+ } ? I : R extends [true, infer Ok] ? (Ok extends {
303
340
  items: (infer I)[];
304
- } ? I : never : never;
341
+ } ? I : never) : never;
305
342
  /**
306
343
  * Extract the item type from an action function's return type
307
344
  */
@@ -373,9 +410,9 @@ type TDataKitBulkAction<TItem> = {
373
410
  } | string]>;
374
411
  };
375
412
  /**
376
- * Controller for external table manipulation
413
+ * Controller ref for external DataKitTable manipulation
377
414
  */
378
- type TDataKitComponentController<TItem> = {
415
+ type TDataKitController<TItem> = {
379
416
  itemPush: (item: TItem, position?: 0 | 1) => void;
380
417
  refetchData: () => void;
381
418
  deleteBulk: (items: TItem[]) => void;
@@ -405,40 +442,6 @@ type TDataKitRef<T = unknown, R = unknown> = TUseDataKitReturn<T, R>;
405
442
  * with pagination, filtering, and sorting.
406
443
  */
407
444
 
408
- /**
409
- * Extract document type from a Mongoose Model.
410
- */
411
- type TExtractDocType<M> = M extends Model<infer TRawDocType, any, any, any, any, any> ? TRawDocType : never;
412
- /**
413
- * Base options shared by both mongoose and adapter versions
414
- */
415
- type TBaseOptions<TDoc, R> = {
416
- input: TDataKitInput<TDoc>;
417
- item: (item: TDoc) => Promise<R> | R;
418
- filterAllowed?: string[];
419
- maxLimit?: number;
420
- queryAllowed?: (keyof TDoc | string)[];
421
- };
422
- /**
423
- * Options when using a Mongoose model
424
- */
425
- type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
426
- model: M;
427
- adapter?: never;
428
- filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>;
429
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
430
- defaultSort?: TSortOptions<TDoc>;
431
- };
432
- /**
433
- * Options when using a custom adapter
434
- */
435
- type TAdapterOptions<TDoc, R> = TBaseOptions<TDoc, R> & {
436
- adapter: TDataKitAdapter<TDoc>;
437
- model?: never;
438
- filter?: never;
439
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, unknown>;
440
- defaultSort?: never;
441
- };
442
445
  /**
443
446
  * Server action with Mongoose model (auto-infers document type)
444
447
  */
@@ -458,7 +461,6 @@ declare const mongooseAdapter: <DocType = unknown>(model: TMongoModel<DocType>,
458
461
  filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<DocType>;
459
462
  filterCustom?: TFilterCustomConfigWithFilter<DocType, TMongoFilterQuery<DocType>>;
460
463
  defaultSort?: TSortOptions<DocType>;
461
- [key: string]: any;
462
464
  }>) => TDataKitAdapter<DocType>;
463
465
 
464
466
  /**
@@ -495,6 +497,10 @@ declare const escapeRegex: (str: string) => string;
495
497
  * ```
496
498
  */
497
499
  declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value: unknown) => TMongoFilterQuery<T>);
500
+ /**
501
+ * Calculate pagination info from page, limit, and total
502
+ */
503
+ declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
498
504
 
499
505
  /**
500
506
  * next-data-kit - useDataKit Hook
@@ -502,7 +508,7 @@ declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value:
502
508
  * React hook for managing next-data-kit state and actions.
503
509
  */
504
510
 
505
- declare const useDataKit: <T = unknown, R = unknown>(props: Readonly<TDataKitControllerOptions<T, R>>) => TUseDataKitReturn<T, R>;
511
+ declare const useDataKit: <T = unknown, R = unknown>(props: Readonly<TUseDataKitOptions<T, R>>) => TUseDataKitReturn<T, R>;
506
512
 
507
513
  /**
508
514
  * next-data-kit - useSelection Hook
@@ -608,4 +614,4 @@ declare const sortEntriesToKey: (sorts: TSortEntry[]) => string;
608
614
  */
609
615
  declare const keyToSortEntries: (key: string) => TSortEntry[];
610
616
 
611
- export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, type TDataKitActions, type TDataKitAdapter, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitComponentController, type TDataKitContextValue, type TDataKitControllerOptions, type TDataKitFilterItem, type TDataKitInput, type TDataKitRef, type TDataKitResult, type TDataKitSelectableItem, type TDataKitState, type TDataKitStateMode, type TExtractDataKitItemType, type TFilterConfig, type TFilterCustomConfig, type TFilterCustomConfigWithFilter, type TMongoFilterOperators, type TMongoFilterQuery, type TMongoModel, type TMongoRootFilterOperators, type TPaginationInfo, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, type TSortEntry, type TSortOptions, type TSortOrder, type TUseDataKitReturn, type TUsePaginationReturn, type TUseSelectionReturn, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
617
+ export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, type TAdapterOptions, type TBaseOptions, type TDataKitActions, type TDataKitAdapter, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitContextValue, type TDataKitController, type TDataKitFilterItem, type TDataKitInput, type TDataKitRef, type TDataKitResult, type TDataKitSelectableItem, type TDataKitState, type TDataKitStateMode, type TExtractDataKitItemType, type TExtractDocType, type TFilterConfig, type TFilterCustomConfig, type TFilterCustomConfigWithFilter, type TMongoFilterOperators, type TMongoFilterQuery, type TMongoModel, type TMongoRootFilterOperators, type TMongooseOptions, type TPaginationInfo, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, type TSortEntry, type TSortOptions, type TSortOrder, type TUseDataKitOptions, type TUseDataKitReturn, type TUsePaginationReturn, type TUseSelectionReturn, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
package/dist/index.js CHANGED
@@ -11,18 +11,44 @@ import { Slot } from '@radix-ui/react-slot';
11
11
  import { cva } from 'class-variance-authority';
12
12
  import * as SelectPrimitive from '@radix-ui/react-select';
13
13
 
14
- // src/types/next-data-kit.ts
15
- var calculatePagination = (page, limit, total) => ({
16
- currentPage: page,
17
- totalPages: Math.ceil(total / limit),
18
- totalItems: total,
19
- itemsPerPage: limit,
20
- hasNextPage: page * limit < total,
21
- hasPrevPage: page > 1
22
- });
23
-
24
14
  // src/server/utils.ts
25
15
  var isProvided = (value) => value !== void 0 && value !== null && value !== "";
16
+ var getValueByPath = (obj, path) => {
17
+ if (!path) return void 0;
18
+ const parts = path.split(".");
19
+ let current = obj;
20
+ for (const part of parts) {
21
+ if (current && typeof current === "object" && part in current) {
22
+ current = current[part];
23
+ } else {
24
+ return void 0;
25
+ }
26
+ }
27
+ return current;
28
+ };
29
+ var matchesExact = (rowValue, needle) => {
30
+ if (Array.isArray(needle)) return needle.includes(rowValue);
31
+ return rowValue === needle;
32
+ };
33
+ var matchesRegexLike = (rowValue, needle) => {
34
+ if (!isProvided(needle)) return true;
35
+ if (rowValue === void 0 || rowValue === null) return false;
36
+ const hay = String(rowValue);
37
+ if (needle instanceof RegExp) return needle.test(hay);
38
+ const n = String(needle);
39
+ return hay.toLowerCase().includes(n.toLowerCase());
40
+ };
41
+ var compareValues = (a, b) => {
42
+ if (a === b) return 0;
43
+ if (a === void 0 || a === null) return -1;
44
+ if (b === void 0 || b === null) return 1;
45
+ if (typeof a === "number" && typeof b === "number") return a - b;
46
+ if (typeof a === "bigint" && typeof b === "bigint") return a < b ? -1 : 1;
47
+ const as = String(a);
48
+ const bs = String(b);
49
+ return as.localeCompare(bs);
50
+ };
51
+ var normalizeSorts = (sorts) => Array.isArray(sorts) ? sorts.filter((s) => !!s?.path && (s.value === 1 || s.value === -1)) : [];
26
52
  var isSafeKey = (key) => {
27
53
  const unsafeKeys = ["__proto__", "constructor", "prototype"];
28
54
  return !unsafeKeys.includes(key);
@@ -43,6 +69,14 @@ var createSearchFilter = (fields) => {
43
69
  };
44
70
  };
45
71
  };
72
+ var calculatePagination = (page, limit, total) => ({
73
+ currentPage: page,
74
+ totalPages: Math.ceil(total / limit),
75
+ totalItems: total,
76
+ itemsPerPage: limit,
77
+ hasNextPage: page * limit < total,
78
+ hasPrevPage: page > 1
79
+ });
46
80
 
47
81
  // src/server/adapters/mongoose.ts
48
82
  var mongooseAdapter = (model, options = {}) => {
@@ -197,43 +231,6 @@ async function dataKitServerAction(props) {
197
231
  }
198
232
 
199
233
  // src/server/adapters/memory.ts
200
- var isProvided2 = (value) => value !== void 0 && value !== null && value !== "";
201
- var getValueByPath = (obj, path) => {
202
- if (!path) return void 0;
203
- const parts = path.split(".");
204
- let current = obj;
205
- for (const part of parts) {
206
- if (current && typeof current === "object" && part in current) {
207
- current = current[part];
208
- } else {
209
- return void 0;
210
- }
211
- }
212
- return current;
213
- };
214
- var matchesExact = (rowValue, needle) => {
215
- if (Array.isArray(needle)) return needle.includes(rowValue);
216
- return rowValue === needle;
217
- };
218
- var matchesRegexLike = (rowValue, needle) => {
219
- if (!isProvided2(needle)) return true;
220
- if (rowValue === void 0 || rowValue === null) return false;
221
- const hay = String(rowValue);
222
- if (needle instanceof RegExp) return needle.test(hay);
223
- const n = String(needle);
224
- return hay.toLowerCase().includes(n.toLowerCase());
225
- };
226
- var compareValues = (a, b) => {
227
- if (a === b) return 0;
228
- if (a === void 0 || a === null) return -1;
229
- if (b === void 0 || b === null) return 1;
230
- if (typeof a === "number" && typeof b === "number") return a - b;
231
- if (typeof a === "bigint" && typeof b === "bigint") return a < b ? -1 : 1;
232
- const as = String(a);
233
- const bs = String(b);
234
- return as.localeCompare(bs);
235
- };
236
- var normalizeSorts = (sorts) => Array.isArray(sorts) ? sorts.filter((s) => !!s?.path && (s.value === 1 || s.value === -1)) : [];
237
234
  var adapterMemory = (dataset, options = {}) => {
238
235
  const { defaultFilterType = "exact" } = options;
239
236
  return async ({ filter, sorts, limit, skip, input }) => {
@@ -241,7 +238,7 @@ var adapterMemory = (dataset, options = {}) => {
241
238
  const query = input.query ?? {};
242
239
  let rows = dataset.filter((row) => {
243
240
  for (const [key, value] of Object.entries(query)) {
244
- if (!isProvided2(value)) continue;
241
+ if (!isProvided(value)) continue;
245
242
  const rowValue = getValueByPath(row, key);
246
243
  if (!matchesExact(rowValue, value)) return false;
247
244
  }
@@ -250,7 +247,7 @@ var adapterMemory = (dataset, options = {}) => {
250
247
  const effectiveFilter = filter ?? {};
251
248
  rows = rows.filter((row) => {
252
249
  for (const [key, value] of Object.entries(effectiveFilter)) {
253
- if (!isProvided2(value)) continue;
250
+ if (!isProvided(value)) continue;
254
251
  const config = filterConfig?.[key];
255
252
  const field = config?.field ?? key;
256
253
  const rowValue = getValueByPath(row, field);
@@ -281,6 +278,7 @@ var adapterMemory = (dataset, options = {}) => {
281
278
  };
282
279
  };
283
280
  z.object({
281
+ action: z.literal("FETCH").optional(),
284
282
  page: z.number().int().positive().optional(),
285
283
  limit: z.number().int().positive().optional(),
286
284
  query: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),