@clipboard-health/json-api-nestjs 0.4.0 → 0.4.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/README.md +18 -16
- package/package.json +1 -1
- package/src/lib/query/filterQuery.d.ts +2 -2
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
booleanString,
|
|
30
30
|
cursorPaginationQuery,
|
|
31
31
|
fieldsQuery,
|
|
32
|
+
type FilterMap,
|
|
32
33
|
filterQuery,
|
|
33
34
|
includeQuery,
|
|
34
35
|
sortQuery,
|
|
@@ -43,10 +44,24 @@ import {
|
|
|
43
44
|
|
|
44
45
|
const articleFields = ["title"] as const satisfies readonly ArticleAttributeFields[];
|
|
45
46
|
const userFields = ["age", "dateOfBirth"] as const satisfies readonly UserAttributeFields[];
|
|
46
|
-
const
|
|
47
|
+
const userIncludeFields = [
|
|
47
48
|
"articles",
|
|
48
49
|
"articles.comments",
|
|
49
50
|
] as const satisfies readonly UserIncludeFields[];
|
|
51
|
+
const userFilterMap = {
|
|
52
|
+
age: {
|
|
53
|
+
filters: ["eq", "gt"],
|
|
54
|
+
schema: z.coerce.number().int().positive().max(125),
|
|
55
|
+
},
|
|
56
|
+
isActive: {
|
|
57
|
+
filters: ["eq"],
|
|
58
|
+
schema: booleanString,
|
|
59
|
+
},
|
|
60
|
+
dateOfBirth: {
|
|
61
|
+
filters: ["gte"],
|
|
62
|
+
schema: z.coerce.date().min(new Date("1900-01-01")).max(new Date()),
|
|
63
|
+
},
|
|
64
|
+
} as const satisfies FilterMap<UserAttributeFields>;
|
|
50
65
|
|
|
51
66
|
/**
|
|
52
67
|
* Disclaimer: Just because JSON:API supports robust querying doesn’t mean your service should
|
|
@@ -60,22 +75,9 @@ export const query = z
|
|
|
60
75
|
.object({
|
|
61
76
|
...cursorPaginationQuery(),
|
|
62
77
|
...fieldsQuery({ user: userFields, article: articleFields }),
|
|
63
|
-
...filterQuery(
|
|
64
|
-
age: {
|
|
65
|
-
filters: ["eq", "gt"],
|
|
66
|
-
schema: z.coerce.number().int().positive().max(125),
|
|
67
|
-
},
|
|
68
|
-
isActive: {
|
|
69
|
-
filters: ["eq"],
|
|
70
|
-
schema: booleanString,
|
|
71
|
-
},
|
|
72
|
-
dateOfBirth: {
|
|
73
|
-
filters: ["gte"],
|
|
74
|
-
schema: z.coerce.date().min(new Date("1900-01-01")).max(new Date()),
|
|
75
|
-
},
|
|
76
|
-
}),
|
|
78
|
+
...filterQuery(userFilterMap),
|
|
77
79
|
...sortQuery(userFields),
|
|
78
|
-
...includeQuery(
|
|
80
|
+
...includeQuery(userIncludeFields),
|
|
79
81
|
})
|
|
80
82
|
.strict();
|
|
81
83
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Field } from "../types";
|
|
3
3
|
export type Filter = "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
|
|
4
|
-
export type FilterMap = Record<
|
|
4
|
+
export type FilterMap<FieldT extends Field = Field> = Record<FieldT, {
|
|
5
5
|
filters: readonly [Filter, ...Filter[]];
|
|
6
6
|
schema: z.ZodTypeAny;
|
|
7
7
|
}>;
|