next-data-kit 9.9.2 → 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 +121 -89
  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 -99
  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.cjs DELETED
@@ -1,300 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkMTJATM72_cjs = require('./chunk-MTJATM72.cjs');
4
- var chunk5TIEIY7M_cjs = require('./chunk-5TIEIY7M.cjs');
5
-
6
- // src/server/adapters/mongoose.ts
7
- var mongooseAdapter = (model, options = {}) => {
8
- const { filter: customFilter, filterCustom, defaultSort = { _id: -1 } } = options;
9
- return async ({ filter, sorts, limit, skip, input }) => {
10
- let sortOption;
11
- if (input.sort && Object.keys(input.sort).length > 0) {
12
- sortOption = input.sort;
13
- } else if (sorts && sorts.length > 0) {
14
- sortOption = sorts.reduce((acc, s) => {
15
- if (s?.path && (s.value === 1 || s.value === -1)) {
16
- acc[s.path] = s.value;
17
- }
18
- return acc;
19
- }, {});
20
- } else {
21
- sortOption = defaultSort;
22
- }
23
- let filterQuery = {};
24
- if (input.query) {
25
- Object.entries(input.query).forEach(([key, value]) => {
26
- if (chunkMTJATM72_cjs.isProvided(value) && chunkMTJATM72_cjs.isSafeKey(key)) {
27
- filterQuery[key] = value;
28
- }
29
- });
30
- }
31
- if (customFilter) {
32
- const customQuery = typeof customFilter === "function" ? customFilter(filter) : customFilter;
33
- filterQuery = { ...filterQuery, ...customQuery };
34
- }
35
- if (filter && !customFilter) {
36
- if (input.filterConfig) {
37
- Object.entries(filter).forEach(([key, value]) => {
38
- if (filterCustom && filterCustom[key]) return;
39
- if (chunkMTJATM72_cjs.isProvided(value) && chunkMTJATM72_cjs.isSafeKey(key) && input.filterConfig?.[key]) {
40
- const config = input.filterConfig[key];
41
- const fieldName = config?.field ?? key;
42
- if (config?.type === "REGEX") {
43
- filterQuery[fieldName] = {
44
- $regex: chunkMTJATM72_cjs.escapeRegex(String(value)),
45
- $options: "i"
46
- };
47
- } else if (config?.type === "EXACT") {
48
- filterQuery[fieldName] = value;
49
- }
50
- }
51
- });
52
- } else {
53
- Object.entries(filter).forEach(([key, value]) => {
54
- if (filterCustom && filterCustom[key]) return;
55
- if (chunkMTJATM72_cjs.isProvided(value) && chunkMTJATM72_cjs.isSafeKey(key)) {
56
- if (typeof value === "string") {
57
- filterQuery[key] = {
58
- $regex: chunkMTJATM72_cjs.escapeRegex(value),
59
- $options: "i"
60
- };
61
- } else if (typeof value === "number" || typeof value === "boolean") {
62
- filterQuery[key] = value;
63
- }
64
- }
65
- });
66
- }
67
- }
68
- if (filterCustom && filter) {
69
- Object.entries(filter).forEach(([key, value]) => {
70
- if (chunkMTJATM72_cjs.isProvided(value) && chunkMTJATM72_cjs.isSafeKey(key) && filterCustom[key]) {
71
- const customFilter2 = filterCustom[key](value);
72
- filterQuery = { ...filterQuery, ...customFilter2 };
73
- }
74
- });
75
- }
76
- const total = await model.countDocuments(filterQuery);
77
- const items = await model.find(filterQuery).sort(sortOption).limit(limit).skip(skip);
78
- return { items, total };
79
- };
80
- };
81
-
82
- // src/server/action.ts
83
- async function executeDataKit(input, adapter, item, maxLimit, filterAllowed, queryAllowed, sortAllowed) {
84
- if (input.query) {
85
- const safeQuery = {};
86
- Object.keys(input.query).forEach((key) => {
87
- if (queryAllowed && !queryAllowed.includes(key)) {
88
- throw new Error(`[Security] Query field '${key}' is not allowed.`);
89
- }
90
- const val = input.query[key];
91
- if (val !== null && typeof val === "object") {
92
- throw new Error(`[Security] Query value for '${key}' must be a primitive.`);
93
- }
94
- if (val !== void 0) {
95
- safeQuery[key] = val;
96
- }
97
- });
98
- input.query = safeQuery;
99
- }
100
- if (input.filter) {
101
- const safeFilter = {};
102
- Object.keys(input.filter).forEach((key) => {
103
- if (filterAllowed && !filterAllowed.includes(key)) {
104
- throw new Error(`[Security] Filter field '${key}' is not allowed.`);
105
- }
106
- const val = input.filter[key];
107
- if (val !== null && typeof val === "object") {
108
- throw new Error(`[Security] Filter value for '${key}' must be a primitive.`);
109
- }
110
- if (val !== void 0) {
111
- safeFilter[key] = val;
112
- }
113
- });
114
- input.filter = safeFilter;
115
- }
116
- if (input.sorts && sortAllowed) {
117
- input.sorts.forEach((sort) => {
118
- if (!sortAllowed.includes(sort.path)) {
119
- throw new Error(`[Security] Sort field '${sort.path}' is not allowed.`);
120
- }
121
- });
122
- }
123
- switch (input.action ?? "FETCH") {
124
- case "FETCH": {
125
- if (!input.limit || !input.page) {
126
- throw new Error("Invalid input: missing limit or page");
127
- }
128
- const limit = Math.min(input.limit, maxLimit);
129
- const skip = limit * (input.page - 1);
130
- const { items, total } = await adapter({
131
- filter: input.filter ?? {},
132
- sorts: input.sorts ?? [],
133
- limit,
134
- page: input.page,
135
- skip,
136
- input
137
- });
138
- const processedItems = await Promise.all(items.map((dataItem) => item(dataItem)));
139
- return {
140
- type: "ITEMS",
141
- items: processedItems,
142
- documentTotal: total
143
- };
144
- }
145
- default:
146
- throw new Error(`Unsupported action: ${input.action}`);
147
- }
148
- }
149
- async function dataKitServerAction(props) {
150
- const { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed, sortAllowed } = props;
151
- const filterAllowed = explicitFilterAllowed;
152
- let finalAdapter;
153
- if ("adapter" in props && props.adapter) {
154
- finalAdapter = props.adapter;
155
- } else if ("model" in props && props.model) {
156
- const model = props.model;
157
- finalAdapter = mongooseAdapter(model, {
158
- filter: props.filter,
159
- filterCustom: props.filterCustom,
160
- defaultSort: props.defaultSort
161
- });
162
- } else {
163
- throw new Error("Either model or adapter must be provided");
164
- }
165
- return executeDataKit(input, finalAdapter, item, maxLimit, filterAllowed, queryAllowed, sortAllowed);
166
- }
167
-
168
- // src/server/adapters/memory.ts
169
- var adapterMemory = (dataset, options = {}) => {
170
- const { defaultFilterType = "exact" } = options;
171
- return async ({ filter, sorts, limit, skip, input }) => {
172
- const filterConfig = input.filterConfig;
173
- const query = input.query ?? {};
174
- let rows = dataset.filter((row) => {
175
- for (const [key, value] of Object.entries(query)) {
176
- if (!chunkMTJATM72_cjs.isProvided(value)) continue;
177
- const rowValue = chunkMTJATM72_cjs.getValueByPath(row, key);
178
- if (!chunkMTJATM72_cjs.matchesExact(rowValue, value)) return false;
179
- }
180
- return true;
181
- });
182
- const effectiveFilter = filter ?? {};
183
- rows = rows.filter((row) => {
184
- for (const [key, value] of Object.entries(effectiveFilter)) {
185
- if (!chunkMTJATM72_cjs.isProvided(value)) continue;
186
- const config = filterConfig?.[key];
187
- const field = config?.field ?? key;
188
- const rowValue = chunkMTJATM72_cjs.getValueByPath(row, field);
189
- const type = config?.type ?? defaultFilterType;
190
- if (type === "regex") {
191
- if (!chunkMTJATM72_cjs.matchesRegexLike(rowValue, value)) return false;
192
- } else {
193
- if (!chunkMTJATM72_cjs.matchesExact(rowValue, value)) return false;
194
- }
195
- }
196
- return true;
197
- });
198
- const normalizedSorts = chunkMTJATM72_cjs.normalizeSorts(sorts);
199
- if (normalizedSorts.length > 0) {
200
- rows = [...rows].sort((ra, rb) => {
201
- for (const s of normalizedSorts) {
202
- const av = chunkMTJATM72_cjs.getValueByPath(ra, s.path);
203
- const bv = chunkMTJATM72_cjs.getValueByPath(rb, s.path);
204
- const cmp = chunkMTJATM72_cjs.compareValues(av, bv);
205
- if (cmp !== 0) return s.value === 1 ? cmp : -cmp;
206
- }
207
- return 0;
208
- });
209
- }
210
- const total = rows.length;
211
- const items = rows.slice(skip, skip + limit);
212
- return { items, total };
213
- };
214
- };
215
-
216
- Object.defineProperty(exports, "DataKit", {
217
- enumerable: true,
218
- get: function () { return chunkMTJATM72_cjs.DataKit; }
219
- });
220
- Object.defineProperty(exports, "DataKitContext", {
221
- enumerable: true,
222
- get: function () { return chunkMTJATM72_cjs.DefaultDataKitContext; }
223
- });
224
- Object.defineProperty(exports, "DataKitProvider", {
225
- enumerable: true,
226
- get: function () { return chunkMTJATM72_cjs.DefaultDataKitProvider; }
227
- });
228
- Object.defineProperty(exports, "calculatePagination", {
229
- enumerable: true,
230
- get: function () { return chunkMTJATM72_cjs.calculatePagination; }
231
- });
232
- Object.defineProperty(exports, "createDataKitContext", {
233
- enumerable: true,
234
- get: function () { return chunkMTJATM72_cjs.createDataKitContext; }
235
- });
236
- Object.defineProperty(exports, "createSearchFilter", {
237
- enumerable: true,
238
- get: function () { return chunkMTJATM72_cjs.createSearchFilter; }
239
- });
240
- Object.defineProperty(exports, "escapeRegex", {
241
- enumerable: true,
242
- get: function () { return chunkMTJATM72_cjs.escapeRegex; }
243
- });
244
- Object.defineProperty(exports, "useDataKitContext", {
245
- enumerable: true,
246
- get: function () { return chunkMTJATM72_cjs.useDefaultDataKitContext; }
247
- });
248
- Object.defineProperty(exports, "usePagination", {
249
- enumerable: true,
250
- get: function () { return chunkMTJATM72_cjs.usePagination; }
251
- });
252
- Object.defineProperty(exports, "useSelection", {
253
- enumerable: true,
254
- get: function () { return chunkMTJATM72_cjs.useSelection; }
255
- });
256
- Object.defineProperty(exports, "useSelectionWithTotal", {
257
- enumerable: true,
258
- get: function () { return chunkMTJATM72_cjs.useSelectionWithTotal; }
259
- });
260
- Object.defineProperty(exports, "debounce", {
261
- enumerable: true,
262
- get: function () { return chunk5TIEIY7M_cjs.debounce; }
263
- });
264
- Object.defineProperty(exports, "formatNumber", {
265
- enumerable: true,
266
- get: function () { return chunk5TIEIY7M_cjs.formatNumber; }
267
- });
268
- Object.defineProperty(exports, "getColumnValue", {
269
- enumerable: true,
270
- get: function () { return chunk5TIEIY7M_cjs.getColumnValue; }
271
- });
272
- Object.defineProperty(exports, "getNextSortValue", {
273
- enumerable: true,
274
- get: function () { return chunk5TIEIY7M_cjs.getNextSortValue; }
275
- });
276
- Object.defineProperty(exports, "getSortValue", {
277
- enumerable: true,
278
- get: function () { return chunk5TIEIY7M_cjs.getSortValue; }
279
- });
280
- Object.defineProperty(exports, "keyToSortEntries", {
281
- enumerable: true,
282
- get: function () { return chunk5TIEIY7M_cjs.keyToSortEntries; }
283
- });
284
- Object.defineProperty(exports, "sortEntriesToKey", {
285
- enumerable: true,
286
- get: function () { return chunk5TIEIY7M_cjs.sortEntriesToKey; }
287
- });
288
- Object.defineProperty(exports, "throttle", {
289
- enumerable: true,
290
- get: function () { return chunk5TIEIY7M_cjs.throttle; }
291
- });
292
- Object.defineProperty(exports, "useDataKit", {
293
- enumerable: true,
294
- get: function () { return chunk5TIEIY7M_cjs.useDataKit; }
295
- });
296
- exports.adapterMemory = adapterMemory;
297
- exports.dataKitServerAction = dataKitServerAction;
298
- exports.mongooseAdapter = mongooseAdapter;
299
- //# sourceMappingURL=index.cjs.map
300
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/server/adapters/mongoose.ts","../src/server/action.ts","../src/server/adapters/memory.ts"],"names":["isPro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A;AAC3C,IAAA,OAAO,EAAE,OAAO,KAAA,EAAM;AAAA,EACvB,CAAA;AACD","file":"index.cjs","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"]}
package/dist/index.d.cts DELETED
@@ -1,117 +0,0 @@
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.cjs';
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.cjs';
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-qXbjvUTB.cjs';
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)[];
28
- };
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>;
38
- };
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;
48
- };
49
-
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
- */
96
-
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;
116
-
117
- export { type TAdapterOptions, type TBaseOptions, TDataKitAdapter, TDataKitInput, TDataKitResult, type TExtractDocType, TFilterCustomConfigWithFilter, TMongoFilterQuery, TMongoModel, type TMongooseOptions, TPaginationInfo, TSortOptions, adapterMemory, calculatePagination, createSearchFilter, dataKitServerAction, escapeRegex, mongooseAdapter };
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk5TIEIY7M_cjs = require('../chunk-5TIEIY7M.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "useDataKit", {
8
- enumerable: true,
9
- get: function () { return chunk5TIEIY7M_cjs.useDataKit; }
10
- });
11
- //# sourceMappingURL=hooks.cjs.map
12
- //# sourceMappingURL=hooks.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"hooks.cjs"}
@@ -1 +0,0 @@
1
- export { h as TUseDataKitOptions, u as useDataKit } from '../useDataKit-XFp3_mUc.cjs';
@@ -1 +0,0 @@
1
- export { h as TUseDataKitOptions, u as useDataKit } from '../useDataKit-XFp3_mUc.js';
@@ -1,3 +0,0 @@
1
- export { useDataKit } from '../chunk-VFSNUXOW.js';
2
- //# sourceMappingURL=hooks.js.map
3
- //# sourceMappingURL=hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"hooks.js"}
@@ -1,52 +0,0 @@
1
- /**
2
- * next-data-kit - Server Utilities
3
- */
4
- import type { TMongoFilterQuery, TSortEntry, TPaginationInfo } from '../types';
5
- /**
6
- * Check if a value is provided (not undefined, null, or empty string)
7
- */
8
- export declare const isProvided: (value: unknown) => boolean;
9
- /**
10
- * Get a nested value from an object by path (e.g., 'user.name')
11
- */
12
- export declare const getValueByPath: (obj: unknown, path: string) => unknown;
13
- /**
14
- * Check if a value matches exactly (supports array inclusion)
15
- */
16
- export declare const matchesExact: (rowValue: unknown, needle: unknown) => boolean;
17
- /**
18
- * Check if a value matches a regex-like pattern (case-insensitive)
19
- */
20
- export declare const matchesRegexLike: (rowValue: unknown, needle: unknown) => boolean;
21
- /**
22
- * Compare two values for sorting
23
- */
24
- export declare const compareValues: (a: unknown, b: unknown) => number;
25
- /**
26
- * Normalize and validate sort entries
27
- */
28
- export declare const normalizeSorts: (sorts: TSortEntry[] | undefined) => TSortEntry[];
29
- /**
30
- * Check if a key is safe (not a prototype pollution key)
31
- */
32
- export declare const isSafeKey: (key: string) => boolean;
33
- /**
34
- * Helper to escape regex special characters in a string
35
- */
36
- export declare const escapeRegex: (str: string) => string;
37
- /**
38
- * Create a search filter for multiple fields
39
- *
40
- * @example
41
- * ```typescript
42
- * filterCustom: {
43
- * search: createSearchFilter(['name', 'email', 'phone'])
44
- * }
45
- * ```
46
- */
47
- export declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => ((value: unknown) => TMongoFilterQuery<T>);
48
- /**
49
- * Calculate pagination info from page, limit, and total
50
- */
51
- export declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
52
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,OAAgE,CAAC;AAE7G;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,OAAO,EAAE,MAAM,MAAM,KAAG,OAY3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,OAAO,EAAE,QAAQ,OAAO,KAAG,OAGjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,OAAO,EAAE,QAAQ,OAAO,KAAG,OAQrE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MAWtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,UAAU,EAAE,GAAG,SAAS,KAAG,UAAU,EAAqG,CAAC;AAEjL;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,OAGvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAEzC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,KAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAa7G,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,eAO/E,CAAC"}