@vulog/aima-core 1.2.45 → 1.2.46
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 +86 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @vulog/aima-core
|
|
2
|
+
|
|
3
|
+
Shared types and Zod schema helpers for pagination and patch actions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @vulog/aima-core zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createPaginableOptionsSchema, PaginableOptions, PaginableResponse, PatchAction } from '@vulog/aima-core';
|
|
15
|
+
|
|
16
|
+
// Create a schema for paginated options with custom filters
|
|
17
|
+
const schema = createPaginableOptionsSchema(myFiltersSchema, mySortSchema);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## API Reference
|
|
21
|
+
|
|
22
|
+
### createPaginableOptionsSchema
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
createPaginableOptionsSchema<T, S>(optionsSchema?: T, sortSchema?: S): ZodObject
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Zod schema factory for paginated query options.
|
|
29
|
+
|
|
30
|
+
| Parameter | Type | Description |
|
|
31
|
+
|-----------|------|-------------|
|
|
32
|
+
| `optionsSchema` | `T` (optional) | Zod schema for filter fields — produces a `filters` key when provided |
|
|
33
|
+
| `sortSchema` | `S` (optional) | Zod schema for the `sort` field — defaults to `z.string().optional()` |
|
|
34
|
+
|
|
35
|
+
Generated schema fields:
|
|
36
|
+
|
|
37
|
+
| Field | Type | Default |
|
|
38
|
+
|-------|------|---------|
|
|
39
|
+
| `page` | integer >= 0 | `0` |
|
|
40
|
+
| `pageSize` | integer 1–1000 | `100` |
|
|
41
|
+
| `sort` | from `sortSchema` | `undefined` |
|
|
42
|
+
| `sortDirection` | `'ASC' \| 'DESC'` | `'ASC'` |
|
|
43
|
+
| `filters` | from `optionsSchema` | — (only present when `optionsSchema` is provided) |
|
|
44
|
+
|
|
45
|
+
## Types
|
|
46
|
+
|
|
47
|
+
### PaginableOptions
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// Without filters (T = void):
|
|
51
|
+
type PaginableOptions<T = void, S = string> = {
|
|
52
|
+
page?: number;
|
|
53
|
+
pageSize?: number;
|
|
54
|
+
sort?: S;
|
|
55
|
+
sortDirection?: 'ASC' | 'DESC';
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// With filters (T provided):
|
|
59
|
+
type PaginableOptions<T, S = string> = {
|
|
60
|
+
page?: number;
|
|
61
|
+
pageSize?: number;
|
|
62
|
+
sort?: S;
|
|
63
|
+
sortDirection?: 'ASC' | 'DESC';
|
|
64
|
+
filters?: T;
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### PaginableResponse
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
type PaginableResponse<T> = {
|
|
72
|
+
data: T[];
|
|
73
|
+
page: number;
|
|
74
|
+
pageSize: number;
|
|
75
|
+
total: number;
|
|
76
|
+
totalPages: number;
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### PatchAction
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
type PatchAction<T extends string> =
|
|
84
|
+
| { op: 'add' | 'replace'; path: T; value: string }
|
|
85
|
+
| { op: 'remove'; path: T };
|
|
86
|
+
```
|