next-data-kit 0.0.1
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/LICENSE +21 -0
- package/README.md +478 -0
- package/dist/client/components/data-kit-table.d.ts +29 -0
- package/dist/client/components/data-kit.d.ts +19 -0
- package/dist/client/components/index.d.ts +3 -0
- package/dist/client/components/ui/button.d.ts +14 -0
- package/dist/client/components/ui/checkbox.d.ts +5 -0
- package/dist/client/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/client/components/ui/index.d.ts +9 -0
- package/dist/client/components/ui/pagination.d.ts +14 -0
- package/dist/client/components/ui/popover.d.ts +10 -0
- package/dist/client/components/ui/select.d.ts +18 -0
- package/dist/client/components/ui/switch.d.ts +5 -0
- package/dist/client/components/ui/table.d.ts +11 -0
- package/dist/client/context/index.d.ts +22 -0
- package/dist/client/hooks/index.d.ts +7 -0
- package/dist/client/hooks/useDataKit.d.ts +9 -0
- package/dist/client/hooks/usePagination.d.ts +18 -0
- package/dist/client/hooks/useSelection.d.ts +13 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/utils/cn.d.ts +10 -0
- package/dist/client/utils/index.d.ts +60 -0
- package/dist/client.d.ts +7 -0
- package/dist/index.d.cts +652 -0
- package/dist/index.d.ts +652 -0
- package/dist/react-data-kit-DmTzxNTc.d.cts +225 -0
- package/dist/react-data-kit-DmTzxNTc.d.ts +225 -0
- package/dist/server.cjs +222 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +68 -0
- package/dist/server.d.ts +68 -0
- package/dist/server.js +216 -0
- package/dist/server.js.map +1 -0
- package/dist/types/component.d.ts +106 -0
- package/dist/types/database/mongo.d.ts +129 -0
- package/dist/types/hook.d.ts +100 -0
- package/dist/types/index.cjs +15 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +252 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/react-data-kit.d.ts +95 -0
- package/dist/types/selectable.d.ts +43 -0
- package/package.json +127 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-data-kit - Database Types (Mongo)
|
|
3
|
+
*
|
|
4
|
+
* MongoDB-specific types.
|
|
5
|
+
* Consolidated into a single file for simplicity.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Sort order for database queries
|
|
9
|
+
*/
|
|
10
|
+
export type TSortOrder = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
|
|
11
|
+
/**
|
|
12
|
+
* ObjectId placeholder type - compatible with MongoDB ObjectId.
|
|
13
|
+
*/
|
|
14
|
+
export type TObjectId = {
|
|
15
|
+
toString(): string;
|
|
16
|
+
toHexString(): string;
|
|
17
|
+
equals(otherId: TObjectId | string): boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Generic document type that represents a database document with an ID.
|
|
21
|
+
*/
|
|
22
|
+
export type TDocument<TId = unknown> = {
|
|
23
|
+
_id: TId;
|
|
24
|
+
createdAt?: Date;
|
|
25
|
+
updatedAt?: Date;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Mongo document base (includes common Mongo-only fields).
|
|
29
|
+
*/
|
|
30
|
+
export type TMongoDocument = TDocument<string | TObjectId> & {
|
|
31
|
+
__v?: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Hydrated document type - represents a document with methods.
|
|
35
|
+
*/
|
|
36
|
+
export type THydratedDocument<T, TId = unknown> = T & TDocument<TId>;
|
|
37
|
+
/**
|
|
38
|
+
* Hydrated Mongo document.
|
|
39
|
+
*/
|
|
40
|
+
export type TMongoHydratedDocument<T> = T & TMongoDocument & {
|
|
41
|
+
toObject(): T;
|
|
42
|
+
toJSON(): T;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Filter operators for individual fields (Mongo subset)
|
|
46
|
+
*/
|
|
47
|
+
export type TMongoFilterOperators<T> = {
|
|
48
|
+
$eq?: T;
|
|
49
|
+
$ne?: T;
|
|
50
|
+
$gt?: T;
|
|
51
|
+
$gte?: T;
|
|
52
|
+
$lt?: T;
|
|
53
|
+
$lte?: T;
|
|
54
|
+
$in?: T[];
|
|
55
|
+
$nin?: T[];
|
|
56
|
+
$exists?: boolean;
|
|
57
|
+
$all?: T extends Array<infer U> ? U[] : never;
|
|
58
|
+
$elemMatch?: T extends Array<infer U> ? TMongoFilterQuery<U> : never;
|
|
59
|
+
$size?: number;
|
|
60
|
+
$regex?: string | RegExp;
|
|
61
|
+
$options?: string;
|
|
62
|
+
$type?: string | number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Mongo root operators.
|
|
66
|
+
*/
|
|
67
|
+
export type TMongoRootFilterOperators<T> = {
|
|
68
|
+
$and?: TMongoFilterQuery<T>[];
|
|
69
|
+
$or?: TMongoFilterQuery<T>[];
|
|
70
|
+
$nor?: TMongoFilterQuery<T>[];
|
|
71
|
+
$not?: TMongoFilterQuery<T>;
|
|
72
|
+
$text?: {
|
|
73
|
+
$search: string;
|
|
74
|
+
$language?: string;
|
|
75
|
+
$caseSensitive?: boolean;
|
|
76
|
+
$diacriticSensitive?: boolean;
|
|
77
|
+
};
|
|
78
|
+
$where?: string | ((this: T) => boolean);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Mongo filter query type.
|
|
82
|
+
*/
|
|
83
|
+
export type TMongoFilterQuery<T> = {
|
|
84
|
+
[P in keyof T]?: T[P] | TMongoFilterOperators<T[P]>;
|
|
85
|
+
} & TMongoRootFilterOperators<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Populate options for query builder.
|
|
88
|
+
*/
|
|
89
|
+
export type TPopulateOptions = {
|
|
90
|
+
path: string;
|
|
91
|
+
select?: string | Record<string, 0 | 1>;
|
|
92
|
+
model?: string;
|
|
93
|
+
match?: Record<string, unknown>;
|
|
94
|
+
populate?: TPopulateOptions | TPopulateOptions[];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Query builder for chaining query operations.
|
|
98
|
+
*/
|
|
99
|
+
export type TQueryBuilder<TResult, TQueryHelpers = object> = Promise<TResult> & {
|
|
100
|
+
sort(options: Record<string, TSortOrder>): TQueryBuilder<TResult, TQueryHelpers>;
|
|
101
|
+
limit(count: number): TQueryBuilder<TResult, TQueryHelpers>;
|
|
102
|
+
skip(count: number): TQueryBuilder<TResult, TQueryHelpers>;
|
|
103
|
+
select(fields: string | Record<string, 0 | 1>): TQueryBuilder<TResult, TQueryHelpers>;
|
|
104
|
+
populate(path: string | TPopulateOptions): TQueryBuilder<TResult, TQueryHelpers>;
|
|
105
|
+
lean(): TQueryBuilder<TResult, TQueryHelpers>;
|
|
106
|
+
exec(): Promise<TResult>;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Generic Model type.
|
|
110
|
+
*/
|
|
111
|
+
export type TModel<TRawDocType = unknown, TQueryHelpers = object, TId = unknown, TFilter = unknown> = {
|
|
112
|
+
countDocuments(filter?: TFilter): Promise<number>;
|
|
113
|
+
find(filter?: TFilter): TQueryBuilder<TRawDocType[], TQueryHelpers>;
|
|
114
|
+
findOne(filter?: TFilter): TQueryBuilder<TRawDocType | null, TQueryHelpers>;
|
|
115
|
+
findById(id: TId): TQueryBuilder<TRawDocType | null, TQueryHelpers>;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Convenience alias for a Mongo-backed model.
|
|
119
|
+
*/
|
|
120
|
+
export type TMongoModel<TRawDocType = unknown, TQueryHelpers = object> = TModel<TRawDocType, TQueryHelpers, string | TObjectId, TMongoFilterQuery<TRawDocType>>;
|
|
121
|
+
/**
|
|
122
|
+
* Extract raw document type from a Model
|
|
123
|
+
*/
|
|
124
|
+
export type TExtractDocType<M> = M extends TModel<infer TRawDocType, unknown, unknown, unknown> ? TRawDocType : never;
|
|
125
|
+
/**
|
|
126
|
+
* Extract hydrated document type from a Model
|
|
127
|
+
*/
|
|
128
|
+
export type TExtractHydratedDoc<M> = M extends TModel<infer TRawDocType, unknown, infer TId, unknown> ? THydratedDocument<TRawDocType, TId> : never;
|
|
129
|
+
//# sourceMappingURL=mongo.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-data-kit - Hook Types
|
|
3
|
+
*
|
|
4
|
+
* Types for the react-data-kit hooks and state management.
|
|
5
|
+
*/
|
|
6
|
+
import type { TSortEntry, TFilterConfig, TDataKitInput, TDataKitResult } from './react-data-kit';
|
|
7
|
+
/**
|
|
8
|
+
* React Data Kit controller state
|
|
9
|
+
*/
|
|
10
|
+
export type TDataKitState<T = unknown> = {
|
|
11
|
+
page: number;
|
|
12
|
+
limit: number;
|
|
13
|
+
sorts: TSortEntry[];
|
|
14
|
+
filter: Record<string, unknown>;
|
|
15
|
+
filterConfig?: TFilterConfig;
|
|
16
|
+
query?: Record<string, unknown>;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
items: T[];
|
|
20
|
+
total: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* React Data Kit controller actions
|
|
24
|
+
*/
|
|
25
|
+
export type TDataKitActions<T = unknown, R = unknown> = {
|
|
26
|
+
setPage: (page: number) => void;
|
|
27
|
+
setLimit: (limit: number) => void;
|
|
28
|
+
setSort: (path: string, value: 1 | -1 | null, append?: boolean) => void;
|
|
29
|
+
setSorts: (sorts: TSortEntry[]) => void;
|
|
30
|
+
setFilter: (key: string, value: unknown) => void;
|
|
31
|
+
setFilters: (filters: Record<string, unknown>) => void;
|
|
32
|
+
clearFilters: () => void;
|
|
33
|
+
setQuery: (key: string, value: unknown) => void;
|
|
34
|
+
refresh: () => Promise<void>;
|
|
35
|
+
reset: () => void;
|
|
36
|
+
getInput: () => TDataKitInput<T>;
|
|
37
|
+
setItems: (items: R[]) => void;
|
|
38
|
+
setItemAt: (index: number, item: R) => void;
|
|
39
|
+
deleteItemAt: (index: number) => void;
|
|
40
|
+
itemPush: (item: R, position?: 0 | 1) => void;
|
|
41
|
+
deleteBulk: (items: R[]) => void;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Combined react-data-kit controller return type
|
|
45
|
+
*/
|
|
46
|
+
export type TUseDataKitReturn<T = unknown, R = unknown> = {
|
|
47
|
+
page: number;
|
|
48
|
+
limit: number;
|
|
49
|
+
sorts: TSortEntry[];
|
|
50
|
+
filter: Record<string, unknown>;
|
|
51
|
+
filterConfig?: TFilterConfig;
|
|
52
|
+
query?: Record<string, unknown>;
|
|
53
|
+
items: R[];
|
|
54
|
+
total: number;
|
|
55
|
+
state: {
|
|
56
|
+
isLoading: boolean;
|
|
57
|
+
error: Error | null;
|
|
58
|
+
};
|
|
59
|
+
actions: TDataKitActions<T, R>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* React Data Kit controller options
|
|
63
|
+
*/
|
|
64
|
+
export type TDataKitControllerOptions<T = unknown, R = unknown> = {
|
|
65
|
+
initial?: {
|
|
66
|
+
page?: number;
|
|
67
|
+
limit?: number;
|
|
68
|
+
sorts?: TSortEntry[];
|
|
69
|
+
filter?: Record<string, unknown>;
|
|
70
|
+
query?: Record<string, unknown>;
|
|
71
|
+
};
|
|
72
|
+
state?: 'memory' | 'search-params';
|
|
73
|
+
filterConfig?: TFilterConfig;
|
|
74
|
+
action: (input: TDataKitInput<T>) => Promise<TDataKitResult<R>>;
|
|
75
|
+
onSuccess?: (result: TDataKitResult<R>) => void;
|
|
76
|
+
onError?: (error: Error) => void;
|
|
77
|
+
autoFetch?: boolean;
|
|
78
|
+
debounce?: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Column definition for react-data-kit (headless)
|
|
82
|
+
*/
|
|
83
|
+
export type TDataKitColumn<T = unknown> = {
|
|
84
|
+
id: string;
|
|
85
|
+
header: string;
|
|
86
|
+
accessor: keyof T | ((item: T) => unknown);
|
|
87
|
+
sortable?: boolean;
|
|
88
|
+
sortPath?: string;
|
|
89
|
+
filterable?: boolean;
|
|
90
|
+
filterKey?: string;
|
|
91
|
+
width?: string | number;
|
|
92
|
+
minWidth?: string | number;
|
|
93
|
+
maxWidth?: string | number;
|
|
94
|
+
align?: 'left' | 'center' | 'right';
|
|
95
|
+
cell?: (value: unknown, item: T, index: number) => React.ReactNode;
|
|
96
|
+
headerCell?: (column: TDataKitColumn<T>) => React.ReactNode;
|
|
97
|
+
hidden?: boolean;
|
|
98
|
+
sticky?: 'left' | 'right';
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=hook.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/next-data-kit.ts
|
|
4
|
+
var calculatePagination = (page, limit, total) => ({
|
|
5
|
+
currentPage: page,
|
|
6
|
+
totalPages: Math.ceil(total / limit),
|
|
7
|
+
totalItems: total,
|
|
8
|
+
itemsPerPage: limit,
|
|
9
|
+
hasNextPage: page * limit < total,
|
|
10
|
+
hasPrevPage: page > 1
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
exports.calculatePagination = calculatePagination;
|
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
|
15
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/next-data-kit.ts"],"names":[],"mappings":";;;AAmHO,IAAM,mBAAA,GAAsB,CAAC,IAAA,EAAc,KAAA,EAAe,KAAA,MAAoC;AAAA,EAChG,WAAA,EAAa,IAAA;AAAA,EACb,UAAA,EAAY,IAAA,CAAK,IAAA,CAAK,KAAA,GAAQ,KAAK,CAAA;AAAA,EACnC,UAAA,EAAY,KAAA;AAAA,EACZ,YAAA,EAAc,KAAA;AAAA,EACd,WAAA,EAAa,OAAO,KAAA,GAAQ,KAAA;AAAA,EAC5B,aAAa,IAAA,GAAO;AACzB,CAAA","file":"index.cjs","sourcesContent":["/**\n * next-data-kit - React Data Kit Types\n *\n * Core types for the next-data-kit server action and components.\n */\n\nimport type { TMongoFilterQuery, TSortOrder } from './database/mongo';\n\n// ** ============================================================================\n// ** Sort Types\n// ** ============================================================================\n\n/**\n * Sort options type that references keys from the item type\n */\nexport type TSortOptions<T> = {\n [K in keyof T]?: TSortOrder;\n};\n\n/**\n * Sort entry for array-based sorting\n */\nexport type TSortEntry = {\n path: string;\n value: 1 | -1;\n};\n\n// ** ============================================================================\n// ** Filter Types\n// ** ============================================================================\n\n/**\n * Filter configuration for automatic filtering\n */\nexport type TFilterConfig = {\n [key: string]: {\n // ** Type of filter matching\n type: 'regex' | 'exact';\n // ** Optional: different database field name\n field?: string;\n };\n};\n\n/**\n * Custom filter configuration\n * Allows defining custom filter functions for specific filter keys\n */\nexport type TFilterCustomConfig<T = unknown> = {\n [id: string]: (data: unknown) => TMongoFilterQuery<T>;\n};\n\n/**\n * Variant of TFilterCustomConfig that allows customizing the returned filter shape.\n * Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.\n */\nexport type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {\n [id: string]: (data: unknown) => TFilter;\n};\n\n// ** ============================================================================\n// ** Input/Output Types\n// ** ============================================================================\n\n/**\n * React Data Kit server action input\n */\nexport type TDataKitInput<T = unknown> = {\n // ** Action type - currently only FETCH is supported\n action?: 'FETCH';\n // ** Current page number (1-indexed)\n page?: number;\n // ** Number of items per page\n limit?: number;\n // ** Legacy sort option\n sort?: TSortOptions<T>;\n // ** Multi-sort as an array\n sorts?: TSortEntry[];\n // ** Query parameters for exact match filtering\n query?: Record<string, unknown>;\n // ** Filter parameters\n filter?: Record<string, unknown>;\n // ** Filter configuration for automatic filtering\n filterConfig?: TFilterConfig;\n // ** Custom filter configuration\n filterCustom?: TFilterCustomConfig<T>;\n};\n\n/**\n * React Data Kit server action result\n */\nexport type TDataKitResult<R> = {\n type: 'ITEMS';\n items: R[];\n documentTotal: number;\n};\n\n// ** ============================================================================\n// ** Pagination Types\n// ** ============================================================================\n\n/**\n * Pagination info for client-side use\n */\nexport type TPaginationInfo = {\n currentPage: number;\n totalPages: number;\n totalItems: number;\n itemsPerPage: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n};\n\n/**\n * Calculate pagination info from next-data-kit result\n */\nexport const calculatePagination = (page: number, limit: number, total: number): TPaginationInfo => ({\n currentPage: page,\n totalPages: Math.ceil(total / limit),\n totalItems: total,\n itemsPerPage: limit,\n hasNextPage: page * limit < total,\n hasPrevPage: page > 1,\n});\n\n// ** ============================================================================\n// ** Adapter Types\n// ** ============================================================================\n\n/**\n * React Data Kit Adapter Interface\n * Defines the contract for a database adapter.\n */\nexport type TDataKitAdapter<T> = (params: Readonly<{\n filter: Record<string, unknown>;\n sorts: TSortEntry[];\n limit: number;\n page: number;\n skip: number;\n input: TDataKitInput<T>;\n}>) => Promise<{ items: T[]; total: number }>;\n"]}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { r as TSortEntry, l as TFilterConfig, T as TDataKitInput, f as TDataKitResult } from '../react-data-kit-DmTzxNTc.cjs';
|
|
2
|
+
export { a as TDataKitAdapter, s as TDocument, g as TExtractDocType, v as TExtractHydratedDoc, k as TFilterCustomConfig, d as TFilterCustomConfigWithFilter, i as THydratedDocument, h as TModel, p as TMongoDocument, m as TMongoFilterOperators, c as TMongoFilterQuery, q as TMongoHydratedDocument, b as TMongoModel, n as TMongoRootFilterOperators, o as TObjectId, w as TPaginationInfo, u as TPopulateOptions, t as TQueryBuilder, e as TSortOptions, j as TSortOrder, x as calculatePagination } from '../react-data-kit-DmTzxNTc.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* react-data-kit - Hook Types
|
|
6
|
+
*
|
|
7
|
+
* Types for the react-data-kit hooks and state management.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* React Data Kit controller state
|
|
12
|
+
*/
|
|
13
|
+
type TDataKitState<T = unknown> = {
|
|
14
|
+
page: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
sorts: TSortEntry[];
|
|
17
|
+
filter: Record<string, unknown>;
|
|
18
|
+
filterConfig?: TFilterConfig;
|
|
19
|
+
query?: Record<string, unknown>;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
error: Error | null;
|
|
22
|
+
items: T[];
|
|
23
|
+
total: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* React Data Kit controller actions
|
|
27
|
+
*/
|
|
28
|
+
type TDataKitActions<T = unknown, R = unknown> = {
|
|
29
|
+
setPage: (page: number) => void;
|
|
30
|
+
setLimit: (limit: number) => void;
|
|
31
|
+
setSort: (path: string, value: 1 | -1 | null, append?: boolean) => void;
|
|
32
|
+
setSorts: (sorts: TSortEntry[]) => void;
|
|
33
|
+
setFilter: (key: string, value: unknown) => void;
|
|
34
|
+
setFilters: (filters: Record<string, unknown>) => void;
|
|
35
|
+
clearFilters: () => void;
|
|
36
|
+
setQuery: (key: string, value: unknown) => void;
|
|
37
|
+
refresh: () => Promise<void>;
|
|
38
|
+
reset: () => void;
|
|
39
|
+
getInput: () => TDataKitInput<T>;
|
|
40
|
+
setItems: (items: R[]) => void;
|
|
41
|
+
setItemAt: (index: number, item: R) => void;
|
|
42
|
+
deleteItemAt: (index: number) => void;
|
|
43
|
+
itemPush: (item: R, position?: 0 | 1) => void;
|
|
44
|
+
deleteBulk: (items: R[]) => void;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Combined react-data-kit controller return type
|
|
48
|
+
*/
|
|
49
|
+
type TUseDataKitReturn<T = unknown, R = unknown> = {
|
|
50
|
+
page: number;
|
|
51
|
+
limit: number;
|
|
52
|
+
sorts: TSortEntry[];
|
|
53
|
+
filter: Record<string, unknown>;
|
|
54
|
+
filterConfig?: TFilterConfig;
|
|
55
|
+
query?: Record<string, unknown>;
|
|
56
|
+
items: R[];
|
|
57
|
+
total: number;
|
|
58
|
+
state: {
|
|
59
|
+
isLoading: boolean;
|
|
60
|
+
error: Error | null;
|
|
61
|
+
};
|
|
62
|
+
actions: TDataKitActions<T, R>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* React Data Kit controller options
|
|
66
|
+
*/
|
|
67
|
+
type TDataKitControllerOptions<T = unknown, R = unknown> = {
|
|
68
|
+
initial?: {
|
|
69
|
+
page?: number;
|
|
70
|
+
limit?: number;
|
|
71
|
+
sorts?: TSortEntry[];
|
|
72
|
+
filter?: Record<string, unknown>;
|
|
73
|
+
query?: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
state?: 'memory' | 'search-params';
|
|
76
|
+
filterConfig?: TFilterConfig;
|
|
77
|
+
action: (input: TDataKitInput<T>) => Promise<TDataKitResult<R>>;
|
|
78
|
+
onSuccess?: (result: TDataKitResult<R>) => void;
|
|
79
|
+
onError?: (error: Error) => void;
|
|
80
|
+
autoFetch?: boolean;
|
|
81
|
+
debounce?: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Column definition for react-data-kit (headless)
|
|
85
|
+
*/
|
|
86
|
+
type TDataKitColumn<T = unknown> = {
|
|
87
|
+
id: string;
|
|
88
|
+
header: string;
|
|
89
|
+
accessor: keyof T | ((item: T) => unknown);
|
|
90
|
+
sortable?: boolean;
|
|
91
|
+
sortPath?: string;
|
|
92
|
+
filterable?: boolean;
|
|
93
|
+
filterKey?: string;
|
|
94
|
+
width?: string | number;
|
|
95
|
+
minWidth?: string | number;
|
|
96
|
+
maxWidth?: string | number;
|
|
97
|
+
align?: 'left' | 'center' | 'right';
|
|
98
|
+
cell?: (value: unknown, item: T, index: number) => React.ReactNode;
|
|
99
|
+
headerCell?: (column: TDataKitColumn<T>) => React.ReactNode;
|
|
100
|
+
hidden?: boolean;
|
|
101
|
+
sticky?: 'left' | 'right';
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* react-data-kit - Selectable Types
|
|
106
|
+
*
|
|
107
|
+
* Types for selectable/multi-select functionality in tables.
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Selection state for a table
|
|
111
|
+
*/
|
|
112
|
+
type TSelectionState<T = string> = {
|
|
113
|
+
selectedIds: Set<T>;
|
|
114
|
+
isAllSelected: boolean;
|
|
115
|
+
isIndeterminate: boolean;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Selection actions for a table
|
|
119
|
+
*/
|
|
120
|
+
type TSelectionActions<T = string> = {
|
|
121
|
+
select: (id: T) => void;
|
|
122
|
+
deselect: (id: T) => void;
|
|
123
|
+
toggle: (id: T) => void;
|
|
124
|
+
selectAll: (ids: T[]) => void;
|
|
125
|
+
deselectAll: () => void;
|
|
126
|
+
toggleAll: (ids: T[]) => void;
|
|
127
|
+
isSelected: (id: T) => boolean;
|
|
128
|
+
getSelectedArray: () => T[];
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Combined selection hook return type
|
|
132
|
+
*/
|
|
133
|
+
type TUseSelectionReturn<T = string> = TSelectionState<T> & TSelectionActions<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Selection mode for tables
|
|
136
|
+
*/
|
|
137
|
+
type TSelectionMode = 'single' | 'multiple' | 'none';
|
|
138
|
+
/**
|
|
139
|
+
* Selectable item type
|
|
140
|
+
*/
|
|
141
|
+
type TSelectable = {
|
|
142
|
+
id: string;
|
|
143
|
+
selected?: boolean;
|
|
144
|
+
disabled?: boolean;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* react-data-kit - Component Types
|
|
149
|
+
*
|
|
150
|
+
* Types for the React Data Kit component and related UI elements.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Extract the item type from a TDataKitResult
|
|
155
|
+
*/
|
|
156
|
+
type TExtractDataKitItemFromResult<R> = R extends TDataKitResult<infer I> ? I : R extends {
|
|
157
|
+
items: (infer I)[];
|
|
158
|
+
} ? I : R extends [true, infer Ok] ? Ok extends {
|
|
159
|
+
items: (infer I)[];
|
|
160
|
+
} ? I : never : never;
|
|
161
|
+
/**
|
|
162
|
+
* Extract the item type from an action function's return type
|
|
163
|
+
*/
|
|
164
|
+
type TExtractDataKitItemType<T> = T extends (input: TDataKitInput<unknown>) => infer R ? TExtractDataKitItemFromResult<Awaited<R>> : never;
|
|
165
|
+
/**
|
|
166
|
+
* Column definition for React Data Kit component
|
|
167
|
+
*/
|
|
168
|
+
type TDataKitComponentColumn<TItem, TRowState = unknown> = {
|
|
169
|
+
head: React.ReactNode;
|
|
170
|
+
body: (props: Readonly<{
|
|
171
|
+
item: TItem;
|
|
172
|
+
index: number;
|
|
173
|
+
state: TRowState;
|
|
174
|
+
setState: React.Dispatch<React.SetStateAction<TRowState>>;
|
|
175
|
+
setItem: (item: TItem) => void;
|
|
176
|
+
deleteItem: () => void;
|
|
177
|
+
}>) => React.ReactNode;
|
|
178
|
+
sortable?: {
|
|
179
|
+
path: string;
|
|
180
|
+
default: 1 | -1 | 0;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Base filter item properties
|
|
185
|
+
*/
|
|
186
|
+
type TDataKitFilterItemBase = {
|
|
187
|
+
id: string;
|
|
188
|
+
label: string;
|
|
189
|
+
placeholder?: string;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Text filter item
|
|
193
|
+
*/
|
|
194
|
+
type TDataKitFilterItemText = TDataKitFilterItemBase & {
|
|
195
|
+
type: 'TEXT';
|
|
196
|
+
defaultValue?: string;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Select filter item - dataset is required
|
|
200
|
+
*/
|
|
201
|
+
type TDataKitFilterItemSelect = TDataKitFilterItemBase & {
|
|
202
|
+
type: 'SELECT';
|
|
203
|
+
dataset: {
|
|
204
|
+
id: string;
|
|
205
|
+
name: string;
|
|
206
|
+
label: string;
|
|
207
|
+
}[];
|
|
208
|
+
defaultValue?: string;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Boolean filter item
|
|
212
|
+
*/
|
|
213
|
+
type TDataKitFilterItemBoolean = TDataKitFilterItemBase & {
|
|
214
|
+
type: 'BOOLEAN';
|
|
215
|
+
defaultValue?: boolean;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Filter item configuration - discriminated union for type safety
|
|
219
|
+
*/
|
|
220
|
+
type TDataKitFilterItem = TDataKitFilterItemText | TDataKitFilterItemSelect | TDataKitFilterItemBoolean;
|
|
221
|
+
/**
|
|
222
|
+
* Bulk action definition for selectable tables
|
|
223
|
+
*/
|
|
224
|
+
type TDataKitBulkAction<TItem> = {
|
|
225
|
+
name: string;
|
|
226
|
+
function: (selectedItems: TItem[]) => Promise<[boolean, {
|
|
227
|
+
deselectAll?: boolean;
|
|
228
|
+
updatedItems?: TItem[];
|
|
229
|
+
} | string]>;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Controller for external table manipulation
|
|
233
|
+
*/
|
|
234
|
+
type TDataKitComponentController<TItem> = {
|
|
235
|
+
itemPush: (item: TItem, position?: 0 | 1) => void;
|
|
236
|
+
refetchData: () => void;
|
|
237
|
+
deleteBulk: (items: TItem[]) => void;
|
|
238
|
+
getSelectedItems: () => TItem[];
|
|
239
|
+
clearSelection: () => void;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Item with ID for selection purposes
|
|
243
|
+
*/
|
|
244
|
+
type TDataKitSelectableItem = {
|
|
245
|
+
id: string | number;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* State persistence mode
|
|
249
|
+
*/
|
|
250
|
+
type TDataKitStateMode = 'memory' | 'search-params';
|
|
251
|
+
|
|
252
|
+
export { type TDataKitActions, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitComponentController, type TDataKitControllerOptions, type TDataKitFilterItem, TDataKitInput, TDataKitResult, type TDataKitSelectableItem, type TDataKitState, type TDataKitStateMode, type TExtractDataKitItemType, TFilterConfig, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, TSortEntry, type TUseDataKitReturn, type TUseSelectionReturn };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @muhgholy/tabler - Types
|
|
3
|
+
*
|
|
4
|
+
* Re-export all types for easy importing.
|
|
5
|
+
*/
|
|
6
|
+
export type { TSortOrder, TObjectId, TDocument, TMongoDocument, THydratedDocument, TMongoHydratedDocument, TMongoFilterOperators, TMongoRootFilterOperators, TMongoFilterQuery, TQueryBuilder, TPopulateOptions, TModel, TMongoModel, TExtractDocType, TExtractHydratedDoc, } from './database/mongo';
|
|
7
|
+
export type { TSortOptions, TSortEntry, TFilterConfig, TFilterCustomConfig, TFilterCustomConfigWithFilter, TDataKitInput, TDataKitResult, TPaginationInfo, TDataKitAdapter, } from './react-data-kit';
|
|
8
|
+
export { calculatePagination } from './react-data-kit';
|
|
9
|
+
export type { TDataKitState, TDataKitActions, TUseDataKitReturn, TDataKitControllerOptions, TDataKitColumn, } from './hook';
|
|
10
|
+
export type { TSelectionState, TSelectionActions, TUseSelectionReturn, TSelectionMode, TSelectable, } from './selectable';
|
|
11
|
+
export type { TExtractDataKitItemType, TDataKitComponentColumn, TDataKitFilterItem, TDataKitBulkAction, TDataKitComponentController, TDataKitSelectableItem, TDataKitStateMode, } from './component';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/types/next-data-kit.ts
|
|
2
|
+
var calculatePagination = (page, limit, total) => ({
|
|
3
|
+
currentPage: page,
|
|
4
|
+
totalPages: Math.ceil(total / limit),
|
|
5
|
+
totalItems: total,
|
|
6
|
+
itemsPerPage: limit,
|
|
7
|
+
hasNextPage: page * limit < total,
|
|
8
|
+
hasPrevPage: page > 1
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export { calculatePagination };
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/next-data-kit.ts"],"names":[],"mappings":";AAmHO,IAAM,mBAAA,GAAsB,CAAC,IAAA,EAAc,KAAA,EAAe,KAAA,MAAoC;AAAA,EAChG,WAAA,EAAa,IAAA;AAAA,EACb,UAAA,EAAY,IAAA,CAAK,IAAA,CAAK,KAAA,GAAQ,KAAK,CAAA;AAAA,EACnC,UAAA,EAAY,KAAA;AAAA,EACZ,YAAA,EAAc,KAAA;AAAA,EACd,WAAA,EAAa,OAAO,KAAA,GAAQ,KAAA;AAAA,EAC5B,aAAa,IAAA,GAAO;AACzB,CAAA","file":"index.js","sourcesContent":["/**\n * next-data-kit - React Data Kit Types\n *\n * Core types for the next-data-kit server action and components.\n */\n\nimport type { TMongoFilterQuery, TSortOrder } from './database/mongo';\n\n// ** ============================================================================\n// ** Sort Types\n// ** ============================================================================\n\n/**\n * Sort options type that references keys from the item type\n */\nexport type TSortOptions<T> = {\n [K in keyof T]?: TSortOrder;\n};\n\n/**\n * Sort entry for array-based sorting\n */\nexport type TSortEntry = {\n path: string;\n value: 1 | -1;\n};\n\n// ** ============================================================================\n// ** Filter Types\n// ** ============================================================================\n\n/**\n * Filter configuration for automatic filtering\n */\nexport type TFilterConfig = {\n [key: string]: {\n // ** Type of filter matching\n type: 'regex' | 'exact';\n // ** Optional: different database field name\n field?: string;\n };\n};\n\n/**\n * Custom filter configuration\n * Allows defining custom filter functions for specific filter keys\n */\nexport type TFilterCustomConfig<T = unknown> = {\n [id: string]: (data: unknown) => TMongoFilterQuery<T>;\n};\n\n/**\n * Variant of TFilterCustomConfig that allows customizing the returned filter shape.\n * Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.\n */\nexport type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {\n [id: string]: (data: unknown) => TFilter;\n};\n\n// ** ============================================================================\n// ** Input/Output Types\n// ** ============================================================================\n\n/**\n * React Data Kit server action input\n */\nexport type TDataKitInput<T = unknown> = {\n // ** Action type - currently only FETCH is supported\n action?: 'FETCH';\n // ** Current page number (1-indexed)\n page?: number;\n // ** Number of items per page\n limit?: number;\n // ** Legacy sort option\n sort?: TSortOptions<T>;\n // ** Multi-sort as an array\n sorts?: TSortEntry[];\n // ** Query parameters for exact match filtering\n query?: Record<string, unknown>;\n // ** Filter parameters\n filter?: Record<string, unknown>;\n // ** Filter configuration for automatic filtering\n filterConfig?: TFilterConfig;\n // ** Custom filter configuration\n filterCustom?: TFilterCustomConfig<T>;\n};\n\n/**\n * React Data Kit server action result\n */\nexport type TDataKitResult<R> = {\n type: 'ITEMS';\n items: R[];\n documentTotal: number;\n};\n\n// ** ============================================================================\n// ** Pagination Types\n// ** ============================================================================\n\n/**\n * Pagination info for client-side use\n */\nexport type TPaginationInfo = {\n currentPage: number;\n totalPages: number;\n totalItems: number;\n itemsPerPage: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n};\n\n/**\n * Calculate pagination info from next-data-kit result\n */\nexport const calculatePagination = (page: number, limit: number, total: number): TPaginationInfo => ({\n currentPage: page,\n totalPages: Math.ceil(total / limit),\n totalItems: total,\n itemsPerPage: limit,\n hasNextPage: page * limit < total,\n hasPrevPage: page > 1,\n});\n\n// ** ============================================================================\n// ** Adapter Types\n// ** ============================================================================\n\n/**\n * React Data Kit Adapter Interface\n * Defines the contract for a database adapter.\n */\nexport type TDataKitAdapter<T> = (params: Readonly<{\n filter: Record<string, unknown>;\n sorts: TSortEntry[];\n limit: number;\n page: number;\n skip: number;\n input: TDataKitInput<T>;\n}>) => Promise<{ items: T[]; total: number }>;\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-data-kit - React Data Kit Types
|
|
3
|
+
*
|
|
4
|
+
* Core types for the react-data-kit server action and components.
|
|
5
|
+
*/
|
|
6
|
+
import type { TMongoFilterQuery, TSortOrder } from './database/mongo';
|
|
7
|
+
/**
|
|
8
|
+
* Sort options type that references keys from the item type
|
|
9
|
+
*/
|
|
10
|
+
export type TSortOptions<T> = {
|
|
11
|
+
[K in keyof T]?: TSortOrder;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Sort entry for array-based sorting
|
|
15
|
+
*/
|
|
16
|
+
export type TSortEntry = {
|
|
17
|
+
path: string;
|
|
18
|
+
value: 1 | -1;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Filter configuration for automatic filtering
|
|
22
|
+
*/
|
|
23
|
+
export type TFilterConfig = {
|
|
24
|
+
[key: string]: {
|
|
25
|
+
type: 'regex' | 'exact';
|
|
26
|
+
field?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Custom filter configuration
|
|
31
|
+
* Allows defining custom filter functions for specific filter keys
|
|
32
|
+
*/
|
|
33
|
+
export type TFilterCustomConfig<T = unknown> = {
|
|
34
|
+
[id: string]: (data: unknown) => TMongoFilterQuery<T>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Variant of TFilterCustomConfig that allows customizing the returned filter shape.
|
|
38
|
+
* Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.
|
|
39
|
+
*/
|
|
40
|
+
export type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {
|
|
41
|
+
[id: string]: (data: unknown) => TFilter;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* React Data Kit server action input
|
|
45
|
+
*/
|
|
46
|
+
export type TDataKitInput<T = unknown> = {
|
|
47
|
+
action?: 'FETCH';
|
|
48
|
+
page?: number;
|
|
49
|
+
limit?: number;
|
|
50
|
+
sort?: TSortOptions<T>;
|
|
51
|
+
sorts?: TSortEntry[];
|
|
52
|
+
query?: Record<string, unknown>;
|
|
53
|
+
filter?: Record<string, unknown>;
|
|
54
|
+
filterConfig?: TFilterConfig;
|
|
55
|
+
filterCustom?: TFilterCustomConfig<T>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* React Data Kit server action result
|
|
59
|
+
*/
|
|
60
|
+
export type TDataKitResult<R> = {
|
|
61
|
+
type: 'ITEMS';
|
|
62
|
+
items: R[];
|
|
63
|
+
documentTotal: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Pagination info for client-side use
|
|
67
|
+
*/
|
|
68
|
+
export type TPaginationInfo = {
|
|
69
|
+
currentPage: number;
|
|
70
|
+
totalPages: number;
|
|
71
|
+
totalItems: number;
|
|
72
|
+
itemsPerPage: number;
|
|
73
|
+
hasNextPage: boolean;
|
|
74
|
+
hasPrevPage: boolean;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Calculate pagination info from react-data-kit result
|
|
78
|
+
*/
|
|
79
|
+
export declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
|
|
80
|
+
/**
|
|
81
|
+
* React Data Kit Adapter Interface
|
|
82
|
+
* Defines the contract for a database adapter.
|
|
83
|
+
*/
|
|
84
|
+
export type TDataKitAdapter<T> = (params: Readonly<{
|
|
85
|
+
filter: Record<string, unknown>;
|
|
86
|
+
sorts: TSortEntry[];
|
|
87
|
+
limit: number;
|
|
88
|
+
page: number;
|
|
89
|
+
skip: number;
|
|
90
|
+
input: TDataKitInput<T>;
|
|
91
|
+
}>) => Promise<{
|
|
92
|
+
items: T[];
|
|
93
|
+
total: number;
|
|
94
|
+
}>;
|
|
95
|
+
//# sourceMappingURL=react-data-kit.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-data-kit - Selectable Types
|
|
3
|
+
*
|
|
4
|
+
* Types for selectable/multi-select functionality in tables.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Selection state for a table
|
|
8
|
+
*/
|
|
9
|
+
export type TSelectionState<T = string> = {
|
|
10
|
+
selectedIds: Set<T>;
|
|
11
|
+
isAllSelected: boolean;
|
|
12
|
+
isIndeterminate: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Selection actions for a table
|
|
16
|
+
*/
|
|
17
|
+
export type TSelectionActions<T = string> = {
|
|
18
|
+
select: (id: T) => void;
|
|
19
|
+
deselect: (id: T) => void;
|
|
20
|
+
toggle: (id: T) => void;
|
|
21
|
+
selectAll: (ids: T[]) => void;
|
|
22
|
+
deselectAll: () => void;
|
|
23
|
+
toggleAll: (ids: T[]) => void;
|
|
24
|
+
isSelected: (id: T) => boolean;
|
|
25
|
+
getSelectedArray: () => T[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Combined selection hook return type
|
|
29
|
+
*/
|
|
30
|
+
export type TUseSelectionReturn<T = string> = TSelectionState<T> & TSelectionActions<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Selection mode for tables
|
|
33
|
+
*/
|
|
34
|
+
export type TSelectionMode = 'single' | 'multiple' | 'none';
|
|
35
|
+
/**
|
|
36
|
+
* Selectable item type
|
|
37
|
+
*/
|
|
38
|
+
export type TSelectable = {
|
|
39
|
+
id: string;
|
|
40
|
+
selected?: boolean;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=selectable.d.ts.map
|