next-data-kit 3.0.1 → 4.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.
- package/README.md +57 -36
- package/dist/client/components/data-kit-table.d.ts.map +1 -1
- package/dist/client/components/data-kit-table.js +0 -3
- package/dist/client/components/data-kit-table.js.map +1 -1
- package/dist/client/components/data-kit.d.ts.map +1 -1
- package/dist/client/components/data-kit.js +0 -3
- package/dist/client/components/data-kit.js.map +1 -1
- package/dist/client/context/index.d.ts.map +1 -1
- package/dist/client/context/index.js +0 -6
- package/dist/client/context/index.js.map +1 -1
- package/dist/client/hooks/useDataKit.d.ts.map +1 -1
- package/dist/client/hooks/useDataKit.js +0 -3
- package/dist/client/hooks/useDataKit.js.map +1 -1
- package/dist/client/hooks/usePagination.d.ts.map +1 -1
- package/dist/client/hooks/usePagination.js +0 -6
- package/dist/client/hooks/usePagination.js.map +1 -1
- package/dist/client/hooks/useSelection.d.ts.map +1 -1
- package/dist/client/hooks/useSelection.js +0 -6
- package/dist/client/hooks/useSelection.js.map +1 -1
- package/dist/client/utils/index.d.ts.map +1 -1
- package/dist/client/utils/index.js +0 -15
- package/dist/client/utils/index.js.map +1 -1
- package/dist/index.cjs +41 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -99
- package/dist/index.d.ts +49 -99
- package/dist/index.js +41 -20
- package/dist/index.js.map +1 -1
- package/dist/next-data-kit-DgLsBFv3.d.cts +143 -0
- package/dist/next-data-kit-DgLsBFv3.d.ts +143 -0
- package/dist/server.cjs +43 -20
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +54 -14
- package/dist/server.d.ts +54 -14
- package/dist/server.js +42 -21
- package/dist/server.js.map +1 -1
- package/dist/types/component.d.ts.map +1 -1
- package/dist/types/database/mongo.d.ts +5 -87
- package/dist/types/database/mongo.d.ts.map +1 -1
- package/dist/types/database/mongo.js +1 -2
- package/dist/types/database/mongo.js.map +1 -1
- package/dist/types/hook.d.ts.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/next-data-kit.d.ts.map +1 -1
- package/dist/types/next-data-kit.js.map +1 -1
- package/dist/types/selectable.d.ts.map +1 -1
- package/package.json +6 -1
- package/dist/next-data-kit-DBl9PPWh.d.cts +0 -225
- package/dist/next-data-kit-DBl9PPWh.d.ts +0 -225
package/dist/index.cjs
CHANGED
|
@@ -48,6 +48,11 @@ var calculatePagination = (page, limit, total) => ({
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
// src/server/utils.ts
|
|
51
|
+
var isProvided = (value) => value !== void 0 && value !== null && value !== "";
|
|
52
|
+
var isSafeKey = (key) => {
|
|
53
|
+
const unsafeKeys = ["__proto__", "constructor", "prototype"];
|
|
54
|
+
return !unsafeKeys.includes(key);
|
|
55
|
+
};
|
|
51
56
|
var escapeRegex = (str) => {
|
|
52
57
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
58
|
};
|
|
@@ -66,11 +71,6 @@ var createSearchFilter = (fields) => {
|
|
|
66
71
|
};
|
|
67
72
|
|
|
68
73
|
// src/server/adapters/mongoose.ts
|
|
69
|
-
var isProvided = (value) => value !== void 0 && value !== null && value !== "";
|
|
70
|
-
var isSafeKey = (key) => {
|
|
71
|
-
const unsafeKeys = ["__proto__", "constructor", "prototype"];
|
|
72
|
-
return !unsafeKeys.includes(key);
|
|
73
|
-
};
|
|
74
74
|
var mongooseAdapter = (model, options = {}) => {
|
|
75
75
|
const { filter: customFilterFn, filterCustom, defaultSort = { _id: -1 } } = options;
|
|
76
76
|
return async ({ filter, sorts, limit, skip, input }) => {
|
|
@@ -145,9 +145,7 @@ var mongooseAdapter = (model, options = {}) => {
|
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
// src/server/action.ts
|
|
148
|
-
|
|
149
|
-
const { input, adapter, item, maxLimit = 100, filterCustom, queryAllowed } = props;
|
|
150
|
-
const filterAllowed = filterCustom ? Object.keys(filterCustom) : void 0;
|
|
148
|
+
async function executeDataKit(input, adapter, item, maxLimit, filterAllowed, queryAllowed) {
|
|
151
149
|
if (input.query) {
|
|
152
150
|
const safeQuery = {};
|
|
153
151
|
Object.keys(input.query).forEach((key) => {
|
|
@@ -178,7 +176,6 @@ var dataKitServerAction = async (props) => {
|
|
|
178
176
|
});
|
|
179
177
|
input.filter = safeFilter;
|
|
180
178
|
}
|
|
181
|
-
const finalAdapter = typeof adapter === "function" ? adapter : mongooseAdapter(adapter, props);
|
|
182
179
|
switch (input.action ?? "FETCH") {
|
|
183
180
|
case "FETCH": {
|
|
184
181
|
if (!input.limit || !input.page) {
|
|
@@ -186,7 +183,7 @@ var dataKitServerAction = async (props) => {
|
|
|
186
183
|
}
|
|
187
184
|
const limit = Math.min(input.limit, maxLimit);
|
|
188
185
|
const skip = limit * (input.page - 1);
|
|
189
|
-
const { items, total } = await
|
|
186
|
+
const { items, total } = await adapter({
|
|
190
187
|
filter: input.filter ?? {},
|
|
191
188
|
sorts: input.sorts ?? [],
|
|
192
189
|
limit,
|
|
@@ -204,7 +201,26 @@ var dataKitServerAction = async (props) => {
|
|
|
204
201
|
default:
|
|
205
202
|
throw new Error(`Unsupported action: ${input.action}`);
|
|
206
203
|
}
|
|
207
|
-
}
|
|
204
|
+
}
|
|
205
|
+
async function dataKitServerAction(props) {
|
|
206
|
+
const { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed } = props;
|
|
207
|
+
const filterCustom = "filterCustom" in props ? props.filterCustom : void 0;
|
|
208
|
+
const filterAllowed = explicitFilterAllowed ?? (filterCustom ? Object.keys(filterCustom) : void 0);
|
|
209
|
+
let finalAdapter;
|
|
210
|
+
if ("adapter" in props && props.adapter) {
|
|
211
|
+
finalAdapter = props.adapter;
|
|
212
|
+
} else if ("model" in props && props.model) {
|
|
213
|
+
const model = props.model;
|
|
214
|
+
finalAdapter = mongooseAdapter(model, {
|
|
215
|
+
filter: props.filter,
|
|
216
|
+
filterCustom: props.filterCustom,
|
|
217
|
+
defaultSort: props.defaultSort
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
throw new Error("Either model or adapter must be provided");
|
|
221
|
+
}
|
|
222
|
+
return executeDataKit(input, finalAdapter, item, maxLimit, filterAllowed, queryAllowed);
|
|
223
|
+
}
|
|
208
224
|
|
|
209
225
|
// src/server/adapters/memory.ts
|
|
210
226
|
var isProvided2 = (value) => value !== void 0 && value !== null && value !== "";
|
|
@@ -295,15 +311,20 @@ zod.z.object({
|
|
|
295
311
|
limit: zod.z.number().int().positive().optional(),
|
|
296
312
|
query: zod.z.record(zod.z.string(), zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()])).optional(),
|
|
297
313
|
filter: zod.z.record(zod.z.string(), zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()])).optional(),
|
|
298
|
-
filterConfig: zod.z.record(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
314
|
+
filterConfig: zod.z.record(
|
|
315
|
+
zod.z.string(),
|
|
316
|
+
zod.z.object({
|
|
317
|
+
type: zod.z.enum(["REGEX", "EXACT"]),
|
|
318
|
+
field: zod.z.string().optional()
|
|
319
|
+
})
|
|
320
|
+
).optional(),
|
|
321
|
+
sorts: zod.z.array(
|
|
322
|
+
zod.z.object({
|
|
323
|
+
path: zod.z.string().max(100),
|
|
324
|
+
// Limit path length to prevent abuse
|
|
325
|
+
value: zod.z.literal(-1).or(zod.z.literal(1))
|
|
326
|
+
})
|
|
327
|
+
).max(5).optional(),
|
|
307
328
|
// Limit to 5 sort fields
|
|
308
329
|
sort: zod.z.record(zod.z.string(), zod.z.literal(1).or(zod.z.literal(-1))).optional()
|
|
309
330
|
});
|