next-data-kit 9.9.1 → 10.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 (106) hide show
  1. package/MIGRATION.md +43 -0
  2. package/README.md +107 -782
  3. package/dist/index.d.ts +79 -111
  4. package/dist/index.js +98 -205
  5. package/dist/index.js.map +1 -1
  6. package/dist/server.d.ts +122 -93
  7. package/dist/server.js +96 -285
  8. package/dist/server.js.map +1 -1
  9. package/package.json +50 -104
  10. package/registry/r/data-kit.json +58 -0
  11. package/registry/r/registry.json +23 -0
  12. package/dist/action-DCmAhOQa.d.cts +0 -196
  13. package/dist/action-DCmAhOQa.d.ts +0 -196
  14. package/dist/chunk-5TIEIY7M.cjs +0 -393
  15. package/dist/chunk-5TIEIY7M.cjs.map +0 -1
  16. package/dist/chunk-MTJATM72.cjs +0 -2423
  17. package/dist/chunk-MTJATM72.cjs.map +0 -1
  18. package/dist/chunk-O377UO7C.js +0 -2379
  19. package/dist/chunk-O377UO7C.js.map +0 -1
  20. package/dist/chunk-VFSNUXOW.js +0 -382
  21. package/dist/chunk-VFSNUXOW.js.map +0 -1
  22. package/dist/client/components/data-kit-infinity.d.ts +0 -23
  23. package/dist/client/components/data-kit-infinity.d.ts.map +0 -1
  24. package/dist/client/components/data-kit-table.d.ts +0 -34
  25. package/dist/client/components/data-kit-table.d.ts.map +0 -1
  26. package/dist/client/components/data-kit.d.ts +0 -25
  27. package/dist/client/components/data-kit.d.ts.map +0 -1
  28. package/dist/client/components/index.d.ts +0 -4
  29. package/dist/client/components/index.d.ts.map +0 -1
  30. package/dist/client/components/ui/button.d.ts +0 -14
  31. package/dist/client/components/ui/button.d.ts.map +0 -1
  32. package/dist/client/components/ui/checkbox.d.ts +0 -5
  33. package/dist/client/components/ui/checkbox.d.ts.map +0 -1
  34. package/dist/client/components/ui/dropdown-menu.d.ts +0 -28
  35. package/dist/client/components/ui/dropdown-menu.d.ts.map +0 -1
  36. package/dist/client/components/ui/index.d.ts +0 -8
  37. package/dist/client/components/ui/index.d.ts.map +0 -1
  38. package/dist/client/components/ui/pagination.d.ts +0 -14
  39. package/dist/client/components/ui/pagination.d.ts.map +0 -1
  40. package/dist/client/components/ui/popover.d.ts +0 -10
  41. package/dist/client/components/ui/popover.d.ts.map +0 -1
  42. package/dist/client/components/ui/select.d.ts +0 -18
  43. package/dist/client/components/ui/select.d.ts.map +0 -1
  44. package/dist/client/components/ui/table.d.ts +0 -11
  45. package/dist/client/components/ui/table.d.ts.map +0 -1
  46. package/dist/client/context/index.d.ts +0 -22
  47. package/dist/client/context/index.d.ts.map +0 -1
  48. package/dist/client/hooks/index.d.ts +0 -7
  49. package/dist/client/hooks/index.d.ts.map +0 -1
  50. package/dist/client/hooks/useDataKit.d.ts +0 -9
  51. package/dist/client/hooks/useDataKit.d.ts.map +0 -1
  52. package/dist/client/hooks/usePagination.d.ts +0 -18
  53. package/dist/client/hooks/usePagination.d.ts.map +0 -1
  54. package/dist/client/hooks/useSelection.d.ts +0 -13
  55. package/dist/client/hooks/useSelection.d.ts.map +0 -1
  56. package/dist/client/index.d.ts +0 -11
  57. package/dist/client/index.d.ts.map +0 -1
  58. package/dist/client/utils/cn.d.ts +0 -10
  59. package/dist/client/utils/cn.d.ts.map +0 -1
  60. package/dist/client/utils/index.d.ts +0 -60
  61. package/dist/client/utils/index.d.ts.map +0 -1
  62. package/dist/client.cjs +0 -85
  63. package/dist/client.cjs.map +0 -1
  64. package/dist/client.d.cts +0 -62
  65. package/dist/client.d.ts +0 -7
  66. package/dist/client.d.ts.map +0 -1
  67. package/dist/client.js +0 -4
  68. package/dist/client.js.map +0 -1
  69. package/dist/index-DUVfK8q6.d.ts +0 -284
  70. package/dist/index-qXbjvUTB.d.cts +0 -284
  71. package/dist/index.cjs +0 -300
  72. package/dist/index.cjs.map +0 -1
  73. package/dist/index.d.cts +0 -117
  74. package/dist/internal/hooks.cjs +0 -12
  75. package/dist/internal/hooks.cjs.map +0 -1
  76. package/dist/internal/hooks.d.cts +0 -1
  77. package/dist/internal/hooks.d.ts +0 -1
  78. package/dist/internal/hooks.js +0 -3
  79. package/dist/internal/hooks.js.map +0 -1
  80. package/dist/server/utils.d.ts +0 -52
  81. package/dist/server/utils.d.ts.map +0 -1
  82. package/dist/server.cjs +0 -315
  83. package/dist/server.cjs.map +0 -1
  84. package/dist/server.d.cts +0 -102
  85. package/dist/styles.css +0 -2
  86. package/dist/types/client/component.d.ts +0 -129
  87. package/dist/types/client/component.d.ts.map +0 -1
  88. package/dist/types/client/hook.d.ts +0 -116
  89. package/dist/types/client/hook.d.ts.map +0 -1
  90. package/dist/types/client/selectable.d.ts +0 -43
  91. package/dist/types/client/selectable.d.ts.map +0 -1
  92. package/dist/types/index.cjs +0 -4
  93. package/dist/types/index.cjs.map +0 -1
  94. package/dist/types/index.d.cts +0 -291
  95. package/dist/types/index.d.ts +0 -12
  96. package/dist/types/index.d.ts.map +0 -1
  97. package/dist/types/index.js +0 -3
  98. package/dist/types/index.js.map +0 -1
  99. package/dist/types/next-data-kit.d.ts +0 -95
  100. package/dist/types/next-data-kit.d.ts.map +0 -1
  101. package/dist/types/server/action.d.ts +0 -44
  102. package/dist/types/server/action.d.ts.map +0 -1
  103. package/dist/types/server/database/mongo.d.ts +0 -56
  104. package/dist/types/server/database/mongo.d.ts.map +0 -1
  105. package/dist/useDataKit-XFp3_mUc.d.cts +0 -276
  106. package/dist/useDataKit-XFp3_mUc.d.ts +0 -276
package/dist/index.d.ts CHANGED
@@ -1,117 +1,85 @@
1
- import { T as TDataKitInput, a as TMongoFilterQuery, b as TFilterCustomConfigWithFilter, c as TSortOptions, d as TDataKitAdapter, e as TDataKitResult, f as TMongoModel, g as TPaginationInfo } from './useDataKit-XFp3_mUc.js';
2
- export { p as TDataKitActions, r as TDataKitColumn, o as TDataKitState, m as TFilterConfig, n as TFilterCustomConfig, j as TMongoFilterOperators, k as TMongoRootFilterOperators, l as TSortEntry, i as TSortOrder, h as TUseDataKitOptions, q as TUseDataKitReturn, u as useDataKit } from './useDataKit-XFp3_mUc.js';
3
- import { Model } from 'mongoose';
4
- export { f as DataKit, e as DataKitContext, D as DataKitProvider, y as TDataKitBulkAction, w as TDataKitComponentColumn, m as TDataKitContextValue, z as TDataKitController, x as TDataKitFilterItem, B as TDataKitMemoryMode, C as TDataKitRef, A as TDataKitSelectableItem, v as TExtractDataKitItemType, r as TSelectable, o as TSelectionActions, q as TSelectionMode, n as TSelectionState, T as TUsePaginationReturn, p as TUseSelectionReturn, c as createDataKitContext, k as debounce, j as formatNumber, g as getColumnValue, i as getNextSortValue, h as getSortValue, l as keyToSortEntries, s as sortEntriesToKey, t as throttle, d as useDataKitContext, b as usePagination, u as useSelection, a as useSelectionWithTotal } from './index-DUVfK8q6.js';
5
- import 'react';
6
- import 'react/jsx-runtime';
7
-
8
- /**
9
- * next-data-kit - Server Action Types
10
- *
11
- * Types for the server action and data kit operations.
12
- */
13
-
14
- /**
15
- * Extract document type from a Mongoose Model.
16
- */
17
- type TExtractDocType<M> = M extends Model<infer TRawDocType, any, any, any, any, any> ? TRawDocType : never;
18
- /**
19
- * Base options shared by both mongoose and adapter versions
20
- */
21
- type TBaseOptions<TDoc, R> = {
22
- input: TDataKitInput<TDoc>;
23
- item: (item: TDoc) => Promise<R> | R;
24
- filterAllowed?: string[];
25
- maxLimit?: number;
26
- queryAllowed?: (keyof TDoc | string)[];
27
- sortAllowed?: (keyof TDoc | string)[];
1
+ type TDataKitSort = {
2
+ field: string;
3
+ direction: 'asc' | 'desc';
28
4
  };
29
- /**
30
- * Options when using a Mongoose model
31
- */
32
- type TMongooseOptions<M, TDoc, R> = TBaseOptions<TDoc, R> & {
33
- model: M;
34
- adapter?: never;
35
- filter?: ((filterInput?: Record<string, unknown>) => TMongoFilterQuery<TDoc>) | TMongoFilterQuery<TDoc>;
36
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, TMongoFilterQuery<TDoc>>;
37
- defaultSort?: TSortOptions<TDoc>;
5
+ type TDataKitInput = {
6
+ page: {
7
+ number: number;
8
+ size: number;
9
+ };
10
+ sort: TDataKitSort[];
11
+ filter: Record<string, unknown>;
38
12
  };
39
- /**
40
- * Options when using a custom adapter
41
- */
42
- type TAdapterOptions<TDoc, R> = TBaseOptions<TDoc, R> & {
43
- adapter: TDataKitAdapter<TDoc>;
44
- model?: never;
45
- filter?: never;
46
- filterCustom?: TFilterCustomConfigWithFilter<TDoc, unknown>;
47
- defaultSort?: never;
13
+ type TDataKitResult<TItem> = TDataKitInput & {
14
+ items: TItem[];
15
+ total: number;
48
16
  };
49
17
 
50
- /**
51
- * next-data-kit - Server Action
52
- *
53
- * The main server-side function for handling table data fetching
54
- * with pagination, filtering, and sorting.
55
- */
56
-
57
- /**
58
- * Server action with Mongoose model (auto-infers document type)
59
- */
60
- declare function dataKitServerAction<M extends Model<any>, R = unknown>(props: Readonly<TMongooseOptions<M, TExtractDocType<M>, R>>): Promise<TDataKitResult<R>>;
61
- /**
62
- * Server action with custom adapter
63
- */
64
- declare function dataKitServerAction<TDoc, R = unknown>(props: Readonly<TAdapterOptions<TDoc, R>>): Promise<TDataKitResult<R>>;
65
-
66
- /**
67
- * next-data-kit - Mongoose Adapter
68
- *
69
- * Database adapter for Mongoose/MongoDB.
70
- */
71
-
72
- declare const mongooseAdapter: <DocType = unknown>(model: TMongoModel<DocType>, options?: Readonly<{
73
- filter?: ((filterInput?: Record<string, unknown>) => TMongoFilterQuery<DocType>) | TMongoFilterQuery<DocType>;
74
- filterCustom?: TFilterCustomConfigWithFilter<DocType, TMongoFilterQuery<DocType>>;
75
- defaultSort?: TSortOptions<DocType>;
76
- }>) => TDataKitAdapter<DocType>;
77
-
78
- /**
79
- * next-data-kit - Memory Adapter
80
- *
81
- * In-memory adapter for demos, tests, and local playgrounds.
82
- * Implements the React Data Kit adapter contract over an array dataset.
83
- */
84
-
85
- /**
86
- * Creates an adapter that pages/filters/sorts an in-memory dataset.
87
- */
88
- declare const adapterMemory: <T extends Record<string, unknown>>(dataset: ReadonlyArray<T>, options?: Readonly<{
89
- /** default behavior for filter keys not present in filterConfig */
90
- defaultFilterType?: "regex" | "exact";
91
- }>) => TDataKitAdapter<T>;
92
-
93
- /**
94
- * next-data-kit - Server Utilities
95
- */
18
+ declare const useDataKit: <TItem extends {
19
+ id: string;
20
+ }>(props: Readonly<{
21
+ initial: TDataKitResult<TItem>;
22
+ source: {
23
+ navigate: (url: string) => void;
24
+ refresh?: () => void;
25
+ } | {
26
+ fetch: (input: unknown) => Promise<TDataKitResult<TItem>>;
27
+ url?: boolean;
28
+ };
29
+ key?: string;
30
+ append?: boolean;
31
+ refetch?: {
32
+ intervalMs: number;
33
+ };
34
+ }>) => {
35
+ key: string | undefined;
36
+ items: TItem[];
37
+ total: number;
38
+ page: {
39
+ number: number;
40
+ size: number;
41
+ count: number;
42
+ };
43
+ sort: TDataKitSort[];
44
+ filter: Record<string, unknown>;
45
+ state: {
46
+ isPending: boolean;
47
+ error: Error | null;
48
+ };
49
+ set: {
50
+ page: (number: number) => void;
51
+ size: (size: number) => void;
52
+ sort: (sort: TDataKitSort[]) => void;
53
+ filter: (filter: Record<string, unknown>) => void;
54
+ };
55
+ refresh: () => void;
56
+ reset: () => void;
57
+ item: {
58
+ push: (props: Readonly<{
59
+ item: TItem;
60
+ position?: "start" | "end";
61
+ }>) => void;
62
+ update: (props: Readonly<{
63
+ id: string;
64
+ data: Partial<TItem>;
65
+ }>) => void;
66
+ remove: (props: Readonly<{
67
+ id: string;
68
+ }>) => void;
69
+ };
70
+ selection: {
71
+ ids: string[];
72
+ has: (id: string) => boolean;
73
+ toggle: (id: string) => void;
74
+ all: () => void;
75
+ clear: () => void;
76
+ };
77
+ };
96
78
 
97
- /**
98
- * Helper to escape regex special characters in a string
99
- */
100
- declare const escapeRegex: (str: string) => string;
101
- /**
102
- * Create a search filter for multiple fields
103
- *
104
- * @example
105
- * ```typescript
106
- * filterCustom: {
107
- * search: createSearchFilter(['name', 'email', 'phone'])
108
- * }
109
- * ```
110
- */
111
- declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value: unknown) => TMongoFilterQuery<T>);
112
- /**
113
- * Calculate pagination info from page, limit, and total
114
- */
115
- declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
79
+ declare const urlEncode: (props: Readonly<{
80
+ input: TDataKitInput;
81
+ key?: string;
82
+ search?: string;
83
+ }>) => string;
116
84
 
117
- export { type TAdapterOptions, type TBaseOptions, TDataKitAdapter, TDataKitInput, TDataKitResult, type TExtractDocType, TFilterCustomConfigWithFilter, TMongoFilterQuery, TMongoModel, type TMongooseOptions, TPaginationInfo, TSortOptions, adapterMemory, calculatePagination, createSearchFilter, dataKitServerAction, escapeRegex, mongooseAdapter };
85
+ export { type TDataKitInput, type TDataKitResult, type TDataKitSort, urlEncode, useDataKit };
package/dist/index.js CHANGED
@@ -1,217 +1,110 @@
1
- import { isProvided, isSafeKey, escapeRegex, getValueByPath, matchesExact, matchesRegexLike, normalizeSorts, compareValues } from './chunk-O377UO7C.js';
2
- export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, calculatePagination, createDataKitContext, createSearchFilter, escapeRegex, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal } from './chunk-O377UO7C.js';
3
- export { debounce, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, sortEntriesToKey, throttle, useDataKit } from './chunk-VFSNUXOW.js';
1
+ 'use client';
4
2
 
5
- // src/server/adapters/mongoose.ts
6
- var mongooseAdapter = (model, options = {}) => {
7
- const { filter: customFilter, filterCustom, defaultSort = { _id: -1 } } = options;
8
- return async ({ filter, sorts, limit, skip, input }) => {
9
- let sortOption;
10
- if (input.sort && Object.keys(input.sort).length > 0) {
11
- sortOption = input.sort;
12
- } else if (sorts && sorts.length > 0) {
13
- sortOption = sorts.reduce((acc, s) => {
14
- if (s?.path && (s.value === 1 || s.value === -1)) {
15
- acc[s.path] = s.value;
16
- }
17
- return acc;
18
- }, {});
19
- } else {
20
- sortOption = defaultSort;
21
- }
22
- let filterQuery = {};
23
- if (input.query) {
24
- Object.entries(input.query).forEach(([key, value]) => {
25
- if (isProvided(value) && isSafeKey(key)) {
26
- filterQuery[key] = value;
27
- }
28
- });
29
- }
30
- if (customFilter) {
31
- const customQuery = typeof customFilter === "function" ? customFilter(filter) : customFilter;
32
- filterQuery = { ...filterQuery, ...customQuery };
33
- }
34
- if (filter && !customFilter) {
35
- if (input.filterConfig) {
36
- Object.entries(filter).forEach(([key, value]) => {
37
- if (filterCustom && filterCustom[key]) return;
38
- if (isProvided(value) && isSafeKey(key) && input.filterConfig?.[key]) {
39
- const config = input.filterConfig[key];
40
- const fieldName = config?.field ?? key;
41
- if (config?.type === "REGEX") {
42
- filterQuery[fieldName] = {
43
- $regex: escapeRegex(String(value)),
44
- $options: "i"
45
- };
46
- } else if (config?.type === "EXACT") {
47
- filterQuery[fieldName] = value;
48
- }
49
- }
50
- });
51
- } else {
52
- Object.entries(filter).forEach(([key, value]) => {
53
- if (filterCustom && filterCustom[key]) return;
54
- if (isProvided(value) && isSafeKey(key)) {
55
- if (typeof value === "string") {
56
- filterQuery[key] = {
57
- $regex: escapeRegex(value),
58
- $options: "i"
59
- };
60
- } else if (typeof value === "number" || typeof value === "boolean") {
61
- filterQuery[key] = value;
62
- }
63
- }
64
- });
65
- }
66
- }
67
- if (filterCustom && filter) {
68
- Object.entries(filter).forEach(([key, value]) => {
69
- if (isProvided(value) && isSafeKey(key) && filterCustom[key]) {
70
- const customFilter2 = filterCustom[key](value);
71
- filterQuery = { ...filterQuery, ...customFilter2 };
72
- }
73
- });
74
- }
75
- const total = await model.countDocuments(filterQuery);
76
- const items = await model.find(filterQuery).sort(sortOption).limit(limit).skip(skip);
77
- return { items, total };
3
+ // src/hook/index.ts
4
+ import { useEffect, useState, useTransition } from "react";
5
+
6
+ // src/url/index.ts
7
+ var urlEncode = (props) => {
8
+ const { input, key, search } = props;
9
+ const prefix = key ? `${key}.` : "";
10
+ const params = new URLSearchParams(search);
11
+ [...params.keys()].filter((name) => key ? name.startsWith(prefix) : ["page", "size", "sort"].includes(name) || name in input.filter).forEach((name) => params.delete(name));
12
+ if (input.page.number > 1) params.set(`${prefix}page`, String(input.page.number));
13
+ params.set(`${prefix}size`, String(input.page.size));
14
+ if (input.sort.length) params.set(`${prefix}sort`, input.sort.map((sort) => `${sort.field}.${sort.direction}`).join(","));
15
+ Object.entries(input.filter).forEach(([name, value]) => {
16
+ if (value !== void 0 && value !== null && value !== "") params.set(`${prefix}${name}`, String(value));
17
+ });
18
+ return params.toString();
19
+ };
20
+ var urlDecode = (props) => {
21
+ const { searchParams, key } = props;
22
+ const prefix = key ? `${key}.` : "";
23
+ const entries = (searchParams instanceof URLSearchParams ? [...searchParams.entries()] : Object.entries(searchParams).map(([name, value]) => [name, Array.isArray(value) ? value[0] : value])).filter((entry) => typeof entry[1] === "string" && entry[0].startsWith(prefix)).map(([name, value]) => [name.slice(prefix.length), value]);
24
+ const values = Object.fromEntries(entries);
25
+ return {
26
+ page: { number: values.page, size: values.size },
27
+ sort: (values.sort ?? "").split(",").filter(Boolean).map((sort) => ({ field: sort.slice(0, sort.lastIndexOf(".")), direction: sort.slice(sort.lastIndexOf(".") + 1) })),
28
+ filter: Object.fromEntries(entries.filter(([name]) => !["page", "size", "sort"].includes(name)))
78
29
  };
79
30
  };
80
31
 
81
- // src/server/action.ts
82
- async function executeDataKit(input, adapter, item, maxLimit, filterAllowed, queryAllowed, sortAllowed) {
83
- if (input.query) {
84
- const safeQuery = {};
85
- Object.keys(input.query).forEach((key) => {
86
- if (queryAllowed && !queryAllowed.includes(key)) {
87
- throw new Error(`[Security] Query field '${key}' is not allowed.`);
88
- }
89
- const val = input.query[key];
90
- if (val !== null && typeof val === "object") {
91
- throw new Error(`[Security] Query value for '${key}' must be a primitive.`);
92
- }
93
- if (val !== void 0) {
94
- safeQuery[key] = val;
95
- }
96
- });
97
- input.query = safeQuery;
98
- }
99
- if (input.filter) {
100
- const safeFilter = {};
101
- Object.keys(input.filter).forEach((key) => {
102
- if (filterAllowed && !filterAllowed.includes(key)) {
103
- throw new Error(`[Security] Filter field '${key}' is not allowed.`);
104
- }
105
- const val = input.filter[key];
106
- if (val !== null && typeof val === "object") {
107
- throw new Error(`[Security] Filter value for '${key}' must be a primitive.`);
108
- }
109
- if (val !== void 0) {
110
- safeFilter[key] = val;
111
- }
112
- });
113
- input.filter = safeFilter;
114
- }
115
- if (input.sorts && sortAllowed) {
116
- input.sorts.forEach((sort) => {
117
- if (!sortAllowed.includes(sort.path)) {
118
- throw new Error(`[Security] Sort field '${sort.path}' is not allowed.`);
119
- }
120
- });
32
+ // src/hook/index.ts
33
+ var useDataKit = (props) => {
34
+ const { initial, source, key, append, refetch } = props;
35
+ const [isPending, startTransition] = useTransition();
36
+ const [result, setResult] = useState(initial);
37
+ const [previous, setPrevious] = useState(initial);
38
+ const [error, setError] = useState(null);
39
+ const [selected, setSelected] = useState([]);
40
+ if (initial !== previous) {
41
+ setPrevious(initial);
42
+ setResult(initial);
121
43
  }
122
- switch (input.action ?? "FETCH") {
123
- case "FETCH": {
124
- if (!input.limit || !input.page) {
125
- throw new Error("Invalid input: missing limit or page");
126
- }
127
- const limit = Math.min(input.limit, maxLimit);
128
- const skip = limit * (input.page - 1);
129
- const { items, total } = await adapter({
130
- filter: input.filter ?? {},
131
- sorts: input.sorts ?? [],
132
- limit,
133
- page: input.page,
134
- skip,
135
- input
136
- });
137
- const processedItems = await Promise.all(items.map((dataItem) => item(dataItem)));
138
- return {
139
- type: "ITEMS",
140
- items: processedItems,
141
- documentTotal: total
142
- };
44
+ const go = (input, more) => {
45
+ setError(null);
46
+ if ("navigate" in source) {
47
+ startTransition(() => source.navigate(`${window.location.pathname}?${urlEncode({ input, key, search: window.location.search })}`));
48
+ return;
143
49
  }
144
- default:
145
- throw new Error(`Unsupported action: ${input.action}`);
146
- }
147
- }
148
- async function dataKitServerAction(props) {
149
- const { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed, sortAllowed } = props;
150
- const filterAllowed = explicitFilterAllowed;
151
- let finalAdapter;
152
- if ("adapter" in props && props.adapter) {
153
- finalAdapter = props.adapter;
154
- } else if ("model" in props && props.model) {
155
- const model = props.model;
156
- finalAdapter = mongooseAdapter(model, {
157
- filter: props.filter,
158
- filterCustom: props.filterCustom,
159
- defaultSort: props.defaultSort
160
- });
161
- } else {
162
- throw new Error("Either model or adapter must be provided");
163
- }
164
- return executeDataKit(input, finalAdapter, item, maxLimit, filterAllowed, queryAllowed, sortAllowed);
165
- }
166
-
167
- // src/server/adapters/memory.ts
168
- var adapterMemory = (dataset, options = {}) => {
169
- const { defaultFilterType = "exact" } = options;
170
- return async ({ filter, sorts, limit, skip, input }) => {
171
- const filterConfig = input.filterConfig;
172
- const query = input.query ?? {};
173
- let rows = dataset.filter((row) => {
174
- for (const [key, value] of Object.entries(query)) {
175
- if (!isProvided(value)) continue;
176
- const rowValue = getValueByPath(row, key);
177
- if (!matchesExact(rowValue, value)) return false;
178
- }
179
- return true;
180
- });
181
- const effectiveFilter = filter ?? {};
182
- rows = rows.filter((row) => {
183
- for (const [key, value] of Object.entries(effectiveFilter)) {
184
- if (!isProvided(value)) continue;
185
- const config = filterConfig?.[key];
186
- const field = config?.field ?? key;
187
- const rowValue = getValueByPath(row, field);
188
- const type = config?.type ?? defaultFilterType;
189
- if (type === "regex") {
190
- if (!matchesRegexLike(rowValue, value)) return false;
191
- } else {
192
- if (!matchesExact(rowValue, value)) return false;
193
- }
50
+ startTransition(async () => {
51
+ try {
52
+ const next = await source.fetch(input);
53
+ if (source.url && !more) window.history.pushState(null, "", `${window.location.pathname}?${urlEncode({ input: next, key, search: window.location.search })}`);
54
+ startTransition(() => setResult((current2) => more ? { ...next, items: [...current2.items, ...next.items] } : next));
55
+ } catch (caught) {
56
+ setError(caught instanceof Error ? caught : new Error(String(caught)));
194
57
  }
195
- return true;
196
58
  });
197
- const normalizedSorts = normalizeSorts(sorts);
198
- if (normalizedSorts.length > 0) {
199
- rows = [...rows].sort((ra, rb) => {
200
- for (const s of normalizedSorts) {
201
- const av = getValueByPath(ra, s.path);
202
- const bv = getValueByPath(rb, s.path);
203
- const cmp = compareValues(av, bv);
204
- if (cmp !== 0) return s.value === 1 ? cmp : -cmp;
205
- }
206
- return 0;
207
- });
59
+ };
60
+ const current = { page: result.page, sort: result.sort, filter: result.filter };
61
+ const refresh = () => "navigate" in source ? source.refresh?.() : go(current);
62
+ useEffect(() => {
63
+ if ("navigate" in source || !source.url) return;
64
+ const listener = () => go(urlDecode({ searchParams: new URLSearchParams(window.location.search), key }));
65
+ window.addEventListener("popstate", listener);
66
+ return () => window.removeEventListener("popstate", listener);
67
+ });
68
+ useEffect(() => {
69
+ if (!refetch) return;
70
+ const interval = setInterval(refresh, refetch.intervalMs);
71
+ return () => clearInterval(interval);
72
+ });
73
+ const count = Math.max(1, Math.ceil(result.total / result.page.size));
74
+ return {
75
+ key,
76
+ items: result.items,
77
+ total: result.total,
78
+ page: { number: result.page.number, size: result.page.size, count },
79
+ sort: result.sort,
80
+ filter: result.filter,
81
+ state: { isPending, error },
82
+ set: {
83
+ page: (number) => go({ ...current, page: { ...current.page, number } }, append && number === current.page.number + 1),
84
+ size: (size) => go({ ...current, page: { number: 1, size } }),
85
+ sort: (sort) => go({ ...current, page: { ...current.page, number: 1 }, sort }),
86
+ // ** A changed filter always starts again from page 1
87
+ filter: (filter) => go({ ...current, page: { ...current.page, number: 1 }, filter: { ...current.filter, ...filter } })
88
+ },
89
+ refresh,
90
+ reset: () => go({ page: { number: 1, size: result.page.size }, sort: [], filter: Object.fromEntries(Object.keys(current.filter).map((name) => [name, void 0])) }),
91
+ item: {
92
+ push: (props2) => setResult((value) => ({ ...value, total: value.total + 1, items: props2.position === "end" ? [...value.items, props2.item] : [props2.item, ...value.items] })),
93
+ update: (props2) => setResult((value) => ({ ...value, items: value.items.map((item) => item.id === props2.id ? { ...item, ...props2.data } : item) })),
94
+ remove: (props2) => setResult((value) => ({ ...value, total: value.total - 1, items: value.items.filter((item) => item.id !== props2.id) }))
95
+ },
96
+ selection: {
97
+ ids: selected,
98
+ has: (id) => selected.includes(id),
99
+ toggle: (id) => setSelected((ids) => ids.includes(id) ? ids.filter((value) => value !== id) : [...ids, id]),
100
+ // ** Selects every row on this page, or clears them when they're all selected already
101
+ all: () => setSelected((ids) => result.items.every((item) => ids.includes(item.id)) ? [] : result.items.map((item) => item.id)),
102
+ clear: () => setSelected([])
208
103
  }
209
- const total = rows.length;
210
- const items = rows.slice(skip, skip + limit);
211
- return { items, total };
212
104
  };
213
105
  };
214
-
215
- export { adapterMemory, dataKitServerAction, mongooseAdapter };
216
- //# sourceMappingURL=index.js.map
106
+ export {
107
+ urlEncode,
108
+ useDataKit
109
+ };
217
110
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server/adapters/mongoose.ts","../src/server/action.ts","../src/server/adapters/memory.ts"],"names":["customFilter"],"mappings":";;;;;AASO,IAAM,eAAA,GAAkB,CAC9B,KAAA,EACA,OAAA,GAIK,EAAC,KACwB;AAE9B,EAAA,MAAM,EAAE,QAAQ,YAAA,EAAc,YAAA,EAAc,cAAc,EAAE,GAAA,EAAK,EAAA,EAAG,EAA2B,GAAI,OAAA;AAEnG,EAAA,OAAO,OAAO,EAAE,MAAA,EAAQ,OAAO,KAAA,EAAO,IAAA,EAAM,OAAM,KAAM;AAEvD,IAAA,IAAI,UAAA;AAEJ,IAAA,IAAI,KAAA,CAAM,QAAQ,MAAA,CAAO,IAAA,CAAK,MAAM,IAAI,CAAA,CAAE,SAAS,CAAA,EAAG;AACrD,MAAA,UAAA,GAAa,KAAA,CAAM,IAAA;AAAA,IACpB,CAAA,MAAA,IAAW,KAAA,IAAS,KAAA,CAAM,MAAA,GAAS,CAAA,EAAG;AACrC,MAAA,UAAA,GAAa,KAAA,CAAM,MAAA,CAAmC,CAAC,GAAA,EAAK,CAAA,KAAM;AACj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B;AAChC,UAAA,MAAM,EAAA,GAAK,cAAA,CAAe,EAAA,EAAI,CAAA,CAAE,IAAI,CAAA;AACpC,UAAA,MAAM,EAAA,GAAK,cAAA,CAAe,EAAA,EAAI,CAAA,CAAE,IAAI,CAAA;AACpC,UAAA,MAAM,GAAA,GAAM,aAAA,CAAc,EAAA,EAAI,EAAE,CAAA;AAChC,UAAA,IAAI,QAAQ,CAAA,EAAG,OAAO,EAAE,KAAA,KAAU,CAAA,GAAI,MAAM,CAAC,GAAA;AAAA,QAC9C;AACA,QAAA,OAAO,CAAA;AAAA,MACR,CAAC,CAAA;AAAA,IACF;AAEA,IAAA,MAAM,QAAQ,IAAA,CAAK,MAAA;AACnB,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,IAAA,EAAM,OAAO,KAAK,CAAA;AAC3C,IAAA,OAAO,EAAE,OAAO,KAAA,EAAM;AAAA,EACvB,CAAA;AACD","file":"index.js","sourcesContent":["/**\n * next-data-kit - Mongoose Adapter\n *\n * Database adapter for Mongoose/MongoDB.\n */\n\nimport type { TMongoModel, TMongoFilterQuery, TSortOrder, TSortOptions, TFilterCustomConfigWithFilter, TDataKitAdapter } from '../../types';\nimport { escapeRegex, isProvided, isSafeKey } from '../utils';\n\nexport const mongooseAdapter = <DocType = unknown>(\n\tmodel: TMongoModel<DocType>,\n\toptions: Readonly<{\n\t\tfilter?: ((filterInput?: Record<string, unknown>) => TMongoFilterQuery<DocType>) | TMongoFilterQuery<DocType>;\n\t\tfilterCustom?: TFilterCustomConfigWithFilter<DocType, TMongoFilterQuery<DocType>>;\n\t\tdefaultSort?: TSortOptions<DocType>;\n\t}> = {},\n): TDataKitAdapter<DocType> => {\n\t// ** Deconstruct options\n\tconst { filter: customFilter, filterCustom, defaultSort = { _id: -1 } as TSortOptions<DocType> } = options;\n\n\treturn async ({ filter, sorts, limit, skip, input }) => {\n\t\t// ** Normalize sort\n\t\tlet sortOption: Record<string, TSortOrder>;\n\n\t\tif (input.sort && Object.keys(input.sort).length > 0) {\n\t\t\tsortOption = input.sort as Record<string, TSortOrder>;\n\t\t} else if (sorts && sorts.length > 0) {\n\t\t\tsortOption = sorts.reduce<Record<string, TSortOrder>>((acc, s) => {\n\t\t\t\tif (s?.path && (s.value === 1 || s.value === -1)) {\n\t\t\t\t\tacc[s.path] = s.value;\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {});\n\t\t} else {\n\t\t\tsortOption = defaultSort as Record<string, TSortOrder>;\n\t\t}\n\n\t\t// ** Construct filter query\n\t\tlet filterQuery: TMongoFilterQuery<DocType> = {};\n\n\t\t// ** Query params (exact match)\n\t\tif (input.query) {\n\t\t\tObject.entries(input.query).forEach(([key, value]) => {\n\t\t\t\tif (isProvided(value) && isSafeKey(key)) {\n\t\t\t\t\t(filterQuery as Record<string, unknown>)[key] = value;\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\t// ** Custom filter function or object\n\t\tif (customFilter) {\n\t\t\tconst customQuery = typeof customFilter === 'function' ? customFilter(filter) : customFilter;\n\t\t\tfilterQuery = { ...filterQuery, ...customQuery };\n\t\t}\n\n\t\t// ** User defined filters\n\t\tif (filter && !customFilter) {\n\t\t\tif (input.filterConfig) {\n\t\t\t\tObject.entries(filter).forEach(([key, value]) => {\n\t\t\t\t\t// Skip if handled by filterCustom\n\t\t\t\t\tif (filterCustom && filterCustom[key]) return;\n\n\t\t\t\t\tif (isProvided(value) && isSafeKey(key) && input.filterConfig?.[key]) {\n\t\t\t\t\t\tconst config = input.filterConfig[key];\n\t\t\t\t\t\tconst fieldName = config?.field ?? key;\n\n\t\t\t\t\t\tif (config?.type === 'REGEX') {\n\t\t\t\t\t\t\t(filterQuery as Record<string, unknown>)[fieldName] = {\n\t\t\t\t\t\t\t\t$regex: escapeRegex(String(value)),\n\t\t\t\t\t\t\t\t$options: 'i',\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (config?.type === 'EXACT') {\n\t\t\t\t\t\t\t(filterQuery as Record<string, unknown>)[fieldName] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// ** Default automatic filtering\n\t\t\t\tObject.entries(filter).forEach(([key, value]) => {\n\t\t\t\t\t// Skip if handled by filterCustom\n\t\t\t\t\tif (filterCustom && filterCustom[key]) return;\n\n\t\t\t\t\tif (isProvided(value) && isSafeKey(key)) {\n\t\t\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\t\t\t(filterQuery as Record<string, unknown>)[key] = {\n\t\t\t\t\t\t\t\t$regex: escapeRegex(value),\n\t\t\t\t\t\t\t\t$options: 'i',\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (typeof value === 'number' || typeof value === 'boolean') {\n\t\t\t\t\t\t\t(filterQuery as Record<string, unknown>)[key] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// ** Custom filter logic (filterCustom)\n\t\tif (filterCustom && filter) {\n\t\t\tObject.entries(filter).forEach(([key, value]) => {\n\t\t\t\tif (isProvided(value) && isSafeKey(key) && filterCustom[key]) {\n\t\t\t\t\tconst customFilter = filterCustom[key]!(value);\n\t\t\t\t\tfilterQuery = { ...filterQuery, ...customFilter };\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\t// ** Execute queries\n\t\tconst total = await model.countDocuments(filterQuery as TMongoFilterQuery<unknown>);\n\t\tconst items = (await model\n\t\t\t.find(filterQuery as TMongoFilterQuery<unknown>)\n\t\t\t.sort(sortOption)\n\t\t\t.limit(limit)\n\t\t\t.skip(skip)) as unknown as DocType[];\n\n\t\treturn { items, total };\n\t};\n};\n","/**\n * next-data-kit - Server Action\n *\n * The main server-side function for handling table data fetching\n * with pagination, filtering, and sorting.\n */\n\nimport { mongooseAdapter } from './adapters/mongoose';\nimport type { Model } from 'mongoose';\nimport type { TDataKitInput, TDataKitResult, TDataKitAdapter, TMongoModel, TExtractDocType, TMongooseOptions, TAdapterOptions } from '../types';\n\n/**\n * Core execution logic shared by both overloads\n */\nasync function executeDataKit<TDoc, R>(input: TDataKitInput<TDoc>, adapter: TDataKitAdapter<TDoc>, item: (item: TDoc) => Promise<R> | R, maxLimit: number, filterAllowed?: string[], queryAllowed?: (keyof TDoc | string)[], sortAllowed?: (keyof TDoc | string)[]): Promise<TDataKitResult<R>> {\n\t// Check Query\n\tif (input.query) {\n\t\tconst safeQuery: Record<string, string | number | boolean> = {};\n\t\tObject.keys(input.query).forEach(key => {\n\t\t\tif (queryAllowed && !queryAllowed.includes(key)) {\n\t\t\t\tthrow new Error(`[Security] Query field '${key}' is not allowed.`);\n\t\t\t}\n\t\t\tconst val = input.query![key];\n\t\t\tif (val !== null && typeof val === 'object') {\n\t\t\t\tthrow new Error(`[Security] Query value for '${key}' must be a primitive.`);\n\t\t\t}\n\t\t\tif (val !== undefined) {\n\t\t\t\tsafeQuery[key] = val;\n\t\t\t}\n\t\t});\n\t\tinput.query = safeQuery;\n\t}\n\n\t// Check Filter\n\tif (input.filter) {\n\t\tconst safeFilter: Record<string, string | number | boolean | null> = {};\n\t\tObject.keys(input.filter).forEach(key => {\n\t\t\tif (filterAllowed && !filterAllowed.includes(key)) {\n\t\t\t\tthrow new Error(`[Security] Filter field '${key}' is not allowed.`);\n\t\t\t}\n\t\t\tconst val = input.filter![key];\n\t\t\tif (val !== null && typeof val === 'object') {\n\t\t\t\tthrow new Error(`[Security] Filter value for '${key}' must be a primitive.`);\n\t\t\t}\n\t\t\tif (val !== undefined) {\n\t\t\t\tsafeFilter[key] = val;\n\t\t\t}\n\t\t});\n\t\tinput.filter = safeFilter;\n\t}\n\n\t// Check Sort\n\tif (input.sorts && sortAllowed) {\n\t\tinput.sorts.forEach(sort => {\n\t\t\tif (!sortAllowed.includes(sort.path)) {\n\t\t\t\tthrow new Error(`[Security] Sort field '${sort.path}' is not allowed.`);\n\t\t\t}\n\t\t});\n\t}\n\n\t// Handle action\n\tswitch (input.action ?? 'FETCH') {\n\t\tcase 'FETCH': {\n\t\t\tif (!input.limit || !input.page) {\n\t\t\t\tthrow new Error('Invalid input: missing limit or page');\n\t\t\t}\n\n\t\t\tconst limit = Math.min(input.limit, maxLimit);\n\t\t\tconst skip = limit * (input.page - 1);\n\n\t\t\tconst { items, total } = await adapter({\n\t\t\t\tfilter: input.filter ?? {},\n\t\t\t\tsorts: input.sorts ?? [],\n\t\t\t\tlimit,\n\t\t\t\tpage: input.page,\n\t\t\t\tskip,\n\t\t\t\tinput,\n\t\t\t});\n\n\t\t\tconst processedItems = await Promise.all(items.map(dataItem => item(dataItem)));\n\n\t\t\treturn {\n\t\t\t\ttype: 'ITEMS',\n\t\t\t\titems: processedItems,\n\t\t\t\tdocumentTotal: total,\n\t\t\t};\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported action: ${(input as { action?: string }).action}`);\n\t}\n}\n\n/**\n * Server action with Mongoose model (auto-infers document type)\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function dataKitServerAction<M extends Model<any>, R = unknown>(props: Readonly<TMongooseOptions<M, TExtractDocType<M>, R>>): Promise<TDataKitResult<R>>;\n\n/**\n * Server action with custom adapter\n */\nexport async function dataKitServerAction<TDoc, R = unknown>(props: Readonly<TAdapterOptions<TDoc, R>>): Promise<TDataKitResult<R>>;\n\n/**\n * Implementation\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function dataKitServerAction<M extends Model<any>, TDoc = any, R = unknown>(props: Readonly<TMongooseOptions<M, TDoc, R> | TAdapterOptions<TDoc, R>>): Promise<TDataKitResult<R>> {\n\tconst { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed, sortAllowed } = props;\n\n\t// Determine filterAllowed\n\tconst filterAllowed = explicitFilterAllowed;\n\n\t// Determine adapter\n\tlet finalAdapter: TDataKitAdapter<TDoc>;\n\n\tif ('adapter' in props && props.adapter) {\n\t\tfinalAdapter = props.adapter;\n\t} else if ('model' in props && props.model) {\n\t\tconst model = props.model as unknown as TMongoModel<TDoc>;\n\t\tfinalAdapter = mongooseAdapter(model, {\n\t\t\tfilter: props.filter,\n\t\t\tfilterCustom: props.filterCustom,\n\t\t\tdefaultSort: props.defaultSort,\n\t\t}) as TDataKitAdapter<TDoc>;\n\t} else {\n\t\tthrow new Error('Either model or adapter must be provided');\n\t}\n\n\treturn executeDataKit(input, finalAdapter, item, maxLimit, filterAllowed, queryAllowed, sortAllowed);\n}\n","/**\n * next-data-kit - Memory Adapter\n *\n * In-memory adapter for demos, tests, and local playgrounds.\n * Implements the React Data Kit adapter contract over an array dataset.\n */\n\nimport type { TFilterConfig, TDataKitAdapter } from '../../types';\nimport { isProvided, getValueByPath, matchesExact, matchesRegexLike, compareValues, normalizeSorts } from '../utils';\n\n/**\n * Creates an adapter that pages/filters/sorts an in-memory dataset.\n */\nexport const adapterMemory = <T extends Record<string, unknown>>(\n\tdataset: ReadonlyArray<T>,\n\toptions: Readonly<{\n\t\t/** default behavior for filter keys not present in filterConfig */\n\t\tdefaultFilterType?: 'regex' | 'exact';\n\t}> = {},\n): TDataKitAdapter<T> => {\n\tconst { defaultFilterType = 'exact' } = options;\n\n\treturn async ({ filter, sorts, limit, skip, input }) => {\n\t\tconst filterConfig: TFilterConfig | undefined = input.filterConfig;\n\t\tconst query = input.query ?? {};\n\n\t\t// 1) Apply query (exact match)\n\t\tlet rows = dataset.filter(row => {\n\t\t\tfor (const [key, value] of Object.entries(query)) {\n\t\t\t\tif (!isProvided(value)) continue;\n\t\t\t\tconst rowValue = getValueByPath(row, key);\n\t\t\t\tif (!matchesExact(rowValue, value)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\t\t// 2) Apply filter (via filterConfig when present)\n\t\tconst effectiveFilter = filter ?? {};\n\t\trows = rows.filter(row => {\n\t\t\tfor (const [key, value] of Object.entries(effectiveFilter)) {\n\t\t\t\tif (!isProvided(value)) continue;\n\n\t\t\t\tconst config = filterConfig?.[key];\n\t\t\t\tconst field = config?.field ?? key;\n\t\t\t\tconst rowValue = getValueByPath(row, field);\n\n\t\t\t\tconst type = config?.type ?? defaultFilterType;\n\t\t\t\tif (type === 'regex') {\n\t\t\t\t\tif (!matchesRegexLike(rowValue, value)) return false;\n\t\t\t\t} else {\n\t\t\t\t\tif (!matchesExact(rowValue, value)) return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\t\t// 3) Sort\n\t\tconst normalizedSorts = normalizeSorts(sorts);\n\t\tif (normalizedSorts.length > 0) {\n\t\t\trows = [...rows].sort((ra, rb) => {\n\t\t\t\tfor (const s of normalizedSorts) {\n\t\t\t\t\tconst av = getValueByPath(ra, s.path);\n\t\t\t\t\tconst bv = getValueByPath(rb, s.path);\n\t\t\t\t\tconst cmp = compareValues(av, bv);\n\t\t\t\t\tif (cmp !== 0) return s.value === 1 ? cmp : -cmp;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t});\n\t\t}\n\n\t\tconst total = rows.length;\n\t\tconst items = rows.slice(skip, skip + limit);\n\t\treturn { items, total };\n\t};\n};\n"]}
1
+ {"version":3,"sources":["../src/hook/index.ts","../src/url/index.ts"],"sourcesContent":["import { useEffect, useState, useTransition } from 'react';\nimport type { TDataKitInput, TDataKitResult, TDataKitSort } from '../types';\nimport { urlDecode, urlEncode } from '../url';\n\n// ** One hook for a table's state: page, sort, filter, selection and local item edits\n// ** source.navigate: state lives in the URL and the server page renders the next `initial` (Next: router.push)\n// ** source.fetch: the host's own authed action returns the next result (infinite scroll, apps without server rendering)\nexport const useDataKit = <TItem extends { id: string }>(\n\tprops: Readonly<{\n\t\tinitial: TDataKitResult<TItem>;\n\t\tsource: { navigate: (url: string) => void; refresh?: () => void } | { fetch: (input: unknown) => Promise<TDataKitResult<TItem>>; url?: boolean };\n\t\tkey?: string;\n\t\t// ** fetch only: add the next page under the current items instead of replacing them\n\t\tappend?: boolean;\n\t\trefetch?: { intervalMs: number };\n\t}>,\n) => {\n\t// ** Deconstruct Props\n\tconst { initial, source, key, append, refetch } = props;\n\n\tconst [isPending, startTransition] = useTransition();\n\tconst [result, setResult] = useState(initial);\n\tconst [previous, setPrevious] = useState(initial);\n\tconst [error, setError] = useState<Error | null>(null);\n\tconst [selected, setSelected] = useState<string[]>([]);\n\n\t// ** A new server-rendered `initial` (navigation, router.refresh) replaces local state\n\tif (initial !== previous) {\n\t\tsetPrevious(initial);\n\t\tsetResult(initial);\n\t}\n\n\tconst go = (input: TDataKitInput | unknown, more?: boolean) => {\n\t\tsetError(null);\n\t\tif ('navigate' in source) {\n\t\t\tstartTransition(() => source.navigate(`${window.location.pathname}?${urlEncode({ input: input as TDataKitInput, key, search: window.location.search })}`));\n\t\t\treturn;\n\t\t}\n\t\tstartTransition(async () => {\n\t\t\ttry {\n\t\t\t\tconst next = await source.fetch(input);\n\t\t\t\tif (source.url && !more) window.history.pushState(null, '', `${window.location.pathname}?${urlEncode({ input: next, key, search: window.location.search })}`);\n\t\t\t\tstartTransition(() => setResult((current) => (more ? { ...next, items: [...current.items, ...next.items] } : next)));\n\t\t\t} catch (caught) {\n\t\t\t\tsetError(caught instanceof Error ? caught : new Error(String(caught)));\n\t\t\t}\n\t\t});\n\t};\n\n\tconst current: TDataKitInput = { page: result.page, sort: result.sort, filter: result.filter };\n\tconst refresh = () => ('navigate' in source ? source.refresh?.() : go(current));\n\n\t// ** fetch + url: back/forward re-reads the URL\n\tuseEffect(() => {\n\t\tif ('navigate' in source || !source.url) return;\n\t\tconst listener = () => go(urlDecode({ searchParams: new URLSearchParams(window.location.search), key }));\n\t\twindow.addEventListener('popstate', listener);\n\t\treturn () => window.removeEventListener('popstate', listener);\n\t});\n\n\tuseEffect(() => {\n\t\tif (!refetch) return;\n\t\tconst interval = setInterval(refresh, refetch.intervalMs);\n\t\treturn () => clearInterval(interval);\n\t});\n\n\tconst count = Math.max(1, Math.ceil(result.total / result.page.size));\n\n\treturn {\n\t\tkey,\n\t\titems: result.items,\n\t\ttotal: result.total,\n\t\tpage: { number: result.page.number, size: result.page.size, count },\n\t\tsort: result.sort,\n\t\tfilter: result.filter,\n\t\tstate: { isPending, error },\n\t\tset: {\n\t\t\tpage: (number: number) => go({ ...current, page: { ...current.page, number } }, append && number === current.page.number + 1),\n\t\t\tsize: (size: number) => go({ ...current, page: { number: 1, size } }),\n\t\t\tsort: (sort: TDataKitSort[]) => go({ ...current, page: { ...current.page, number: 1 }, sort }),\n\t\t\t// ** A changed filter always starts again from page 1\n\t\t\tfilter: (filter: Record<string, unknown>) => go({ ...current, page: { ...current.page, number: 1 }, filter: { ...current.filter, ...filter } }),\n\t\t},\n\t\trefresh,\n\t\treset: () => go({ page: { number: 1, size: result.page.size }, sort: [], filter: Object.fromEntries(Object.keys(current.filter).map((name) => [name, undefined])) }),\n\t\titem: {\n\t\t\tpush: (props: Readonly<{ item: TItem; position?: 'start' | 'end' }>) => setResult((value) => ({ ...value, total: value.total + 1, items: props.position === 'end' ? [...value.items, props.item] : [props.item, ...value.items] })),\n\t\t\tupdate: (props: Readonly<{ id: string; data: Partial<TItem> }>) => setResult((value) => ({ ...value, items: value.items.map((item) => (item.id === props.id ? { ...item, ...props.data } : item)) })),\n\t\t\tremove: (props: Readonly<{ id: string }>) => setResult((value) => ({ ...value, total: value.total - 1, items: value.items.filter((item) => item.id !== props.id) })),\n\t\t},\n\t\tselection: {\n\t\t\tids: selected,\n\t\t\thas: (id: string) => selected.includes(id),\n\t\t\ttoggle: (id: string) => setSelected((ids) => (ids.includes(id) ? ids.filter((value) => value !== id) : [...ids, id])),\n\t\t\t// ** Selects every row on this page, or clears them when they're all selected already\n\t\t\tall: () => setSelected((ids) => (result.items.every((item) => ids.includes(item.id)) ? [] : result.items.map((item) => item.id))),\n\t\t\tclear: () => setSelected([]),\n\t\t},\n\t};\n};\n","import type { TDataKitInput } from '../types';\n\n// ** One format for both sides: the hook writes it, kit.parse reads it\n// ** ?page=2&size=20&sort=name.asc,createdAt.desc&search=x — with key \"user\": ?user.page=2&user.sort=…\n\nexport const urlEncode = (props: Readonly<{ input: TDataKitInput; key?: string; search?: string }>) => {\n\t// ** Deconstruct Props\n\tconst { input, key, search } = props;\n\n\tconst prefix = key ? `${key}.` : '';\n\tconst params = new URLSearchParams(search);\n\n\t// ** Drop this kit's old params, keep everything else on the page (other kits, returnUrl, …)\n\t[...params.keys()].filter((name) => (key ? name.startsWith(prefix) : ['page', 'size', 'sort'].includes(name) || name in input.filter)).forEach((name) => params.delete(name));\n\n\tif (input.page.number > 1) params.set(`${prefix}page`, String(input.page.number));\n\tparams.set(`${prefix}size`, String(input.page.size));\n\tif (input.sort.length) params.set(`${prefix}sort`, input.sort.map((sort) => `${sort.field}.${sort.direction}`).join(','));\n\tObject.entries(input.filter).forEach(([name, value]) => {\n\t\tif (value !== undefined && value !== null && value !== '') params.set(`${prefix}${name}`, String(value));\n\t});\n\n\treturn params.toString();\n};\n\n// ** Raw, unvalidated values: kit.schema decides what survives\nexport const urlDecode = (props: Readonly<{ searchParams: URLSearchParams | Record<string, string | string[] | undefined>; key?: string }>) => {\n\t// ** Deconstruct Props\n\tconst { searchParams, key } = props;\n\n\tconst prefix = key ? `${key}.` : '';\n\tconst entries = (searchParams instanceof URLSearchParams ? [...searchParams.entries()] : Object.entries(searchParams).map(([name, value]) => [name, Array.isArray(value) ? value[0] : value] as [string, string | undefined]))\n\t\t.filter((entry): entry is [string, string] => typeof entry[1] === 'string' && entry[0].startsWith(prefix))\n\t\t.map(([name, value]) => [name.slice(prefix.length), value] as const);\n\tconst values = Object.fromEntries(entries);\n\n\treturn {\n\t\tpage: { number: values.page, size: values.size },\n\t\tsort: (values.sort ?? '')\n\t\t\t.split(',')\n\t\t\t.filter(Boolean)\n\t\t\t.map((sort) => ({ field: sort.slice(0, sort.lastIndexOf('.')), direction: sort.slice(sort.lastIndexOf('.') + 1) })),\n\t\tfilter: Object.fromEntries(entries.filter(([name]) => !['page', 'size', 'sort'].includes(name))),\n\t};\n};\n"],"mappings":";;;AAA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