@clipboard-health/json-api-nestjs
Advanced tools
Comparing version
{ | ||
"name": "@clipboard-health/json-api-nestjs", | ||
"description": "Utilities for adhering to the JSON:API specification with NestJS.", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"dependencies": { | ||
@@ -15,2 +15,5 @@ "tslib": "2.7.0", | ||
}, | ||
"scripts": { | ||
"embed": "embedme README.md" | ||
}, | ||
"type": "commonjs", | ||
@@ -17,0 +20,0 @@ "typings": "./src/index.d.ts", |
@@ -27,2 +27,36 @@ # @clipboard-health/json-api-nestjs | ||
// ./examples/query.ts | ||
import { | ||
booleanString, | ||
createCursorPagination, | ||
createFields, | ||
createFilter, | ||
createInclude, | ||
createSort, | ||
} from "@clipboard-health/json-api-nestjs"; | ||
import { z } from "zod"; | ||
export const query = z | ||
.object({ | ||
...createCursorPagination(), | ||
...createFields({ user: ["age", "name"], article: ["title"] }), | ||
...createFilter({ | ||
age: { | ||
filters: ["eq", "gt"], | ||
schema: z.coerce.number().int().positive().max(125), | ||
}, | ||
isActive: { | ||
filters: ["eq"], | ||
schema: booleanString, | ||
}, | ||
dateOfBirth: { | ||
filters: ["gte"], | ||
schema: z.coerce.date().min(new Date("1900-01-01")), | ||
}, | ||
}), | ||
...createSort(["age", "name"]), | ||
...createInclude(["articles", "articles.comments"]), | ||
}) | ||
.strict(); | ||
``` | ||
@@ -29,0 +63,0 @@ |
export * from "./lib/query/createCursorPagination"; | ||
export * from "./lib/query/createFields"; | ||
export * from "./lib/query/createFilter"; | ||
export * from "./lib/query/createInclude"; | ||
export * from "./lib/query/createSort"; | ||
export * from "./lib/schemas"; | ||
export * from "./lib/types"; |
@@ -7,2 +7,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./lib/query/createFilter"), exports); | ||
tslib_1.__exportStar(require("./lib/query/createInclude"), exports); | ||
tslib_1.__exportStar(require("./lib/query/createSort"), exports); | ||
@@ -9,0 +10,0 @@ tslib_1.__exportStar(require("./lib/schemas"), exports); |
import { z } from "zod"; | ||
import { type Field } from "../types"; | ||
export type SortSchema<T extends readonly Field[]> = z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString>>>, Array<`-${T[number]}` | T[number]> | undefined, unknown>>; | ||
/** | ||
@@ -5,0 +4,0 @@ * Creates a Zod schema for JSON:API sort parameters. |
@@ -28,2 +28,3 @@ "use strict"; | ||
message: `Invalid sort field: '${field}'`, | ||
path: ["sort", field], | ||
}); | ||
@@ -30,0 +31,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25558
16.17%35
9.38%380
14.8%66
106.25%4625
-24.44%4
-20%