@clipboard-health/json-api-nestjs 0.3.0 → 0.3.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 +32 -11
- package/package.json +4 -1
- package/src/index.d.ts +5 -5
- package/src/index.js +5 -5
- package/src/index.js.map +1 -1
- package/src/lib/internal/queryFilterPreprocessor.js +2 -2
- package/src/lib/internal/queryFilterPreprocessor.js.map +1 -1
- package/src/lib/query/{createCursorPagination.d.ts → cursorPaginationQuery.d.ts} +11 -3
- package/src/lib/query/{createCursorPagination.js → cursorPaginationQuery.js} +13 -5
- package/src/lib/query/cursorPaginationQuery.js.map +1 -0
- package/src/lib/query/{createFields.d.ts → fieldsQuery.d.ts} +8 -2
- package/src/lib/query/{createFields.js → fieldsQuery.js} +4 -4
- package/src/lib/query/fieldsQuery.js.map +1 -0
- package/src/lib/query/{createFilter.d.ts → filterQuery.d.ts} +1 -1
- package/src/lib/query/{createFilter.js → filterQuery.js} +6 -4
- package/src/lib/query/filterQuery.js.map +1 -0
- package/src/lib/query/includeQuery.d.ts +31 -0
- package/src/lib/query/{createInclude.js → includeQuery.js} +6 -6
- package/src/lib/query/includeQuery.js.map +1 -0
- package/src/lib/query/{createSort.d.ts → sortQuery.d.ts} +1 -1
- package/src/lib/query/{createSort.js → sortQuery.js} +4 -4
- package/src/lib/query/sortQuery.js.map +1 -0
- package/src/lib/types.d.ts +34 -0
- package/src/test/index.d.ts +0 -1
- package/src/test/index.js +0 -1
- package/src/test/index.js.map +1 -1
- package/src/lib/query/createCursorPagination.js.map +0 -1
- package/src/lib/query/createFields.js.map +0 -1
- package/src/lib/query/createFilter.js.map +0 -1
- package/src/lib/query/createInclude.d.ts +0 -12
- package/src/lib/query/createInclude.js.map +0 -1
- package/src/lib/query/createSort.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,19 +27,40 @@ Create Zod schemas for your API's queries:
|
|
|
27
27
|
|
|
28
28
|
import {
|
|
29
29
|
booleanString,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
cursorPaginationQuery,
|
|
31
|
+
fieldsQuery,
|
|
32
|
+
filterQuery,
|
|
33
|
+
includeQuery,
|
|
34
|
+
sortQuery,
|
|
35
35
|
} from "@clipboard-health/json-api-nestjs";
|
|
36
36
|
import { z } from "zod";
|
|
37
37
|
|
|
38
|
+
import {
|
|
39
|
+
type ArticleAttributeFields,
|
|
40
|
+
type UserAttributeFields,
|
|
41
|
+
type UserIncludeFields,
|
|
42
|
+
} from "./contract";
|
|
43
|
+
|
|
44
|
+
const articleFields = ["title"] as const satisfies readonly ArticleAttributeFields[];
|
|
45
|
+
const userFields = ["age", "name"] as const satisfies readonly UserAttributeFields[];
|
|
46
|
+
const includeFields = [
|
|
47
|
+
"articles",
|
|
48
|
+
"articles.comments",
|
|
49
|
+
] as const satisfies readonly UserIncludeFields[];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Disclaimer: Just because JSON:API supports robust querying doesn’t mean your service should
|
|
53
|
+
* implement them as they may require database indexes, which have a cost. **Implement only access
|
|
54
|
+
* patterns required by clients.**
|
|
55
|
+
*
|
|
56
|
+
* The spec says that if clients provide fields the server doesn’t support, it **MUST** return 400
|
|
57
|
+
* Bad Request, hence the `.strict()`.
|
|
58
|
+
*/
|
|
38
59
|
export const query = z
|
|
39
60
|
.object({
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
...
|
|
61
|
+
...cursorPaginationQuery(),
|
|
62
|
+
...fieldsQuery({ user: userFields, article: articleFields }),
|
|
63
|
+
...filterQuery({
|
|
43
64
|
age: {
|
|
44
65
|
filters: ["eq", "gt"],
|
|
45
66
|
schema: z.coerce.number().int().positive().max(125),
|
|
@@ -50,11 +71,11 @@ export const query = z
|
|
|
50
71
|
},
|
|
51
72
|
dateOfBirth: {
|
|
52
73
|
filters: ["gte"],
|
|
53
|
-
schema: z.coerce.date().min(new Date("1900-01-01")),
|
|
74
|
+
schema: z.coerce.date().min(new Date("1900-01-01")).max(new Date()),
|
|
54
75
|
},
|
|
55
76
|
}),
|
|
56
|
-
...
|
|
57
|
-
...
|
|
77
|
+
...sortQuery(userFields),
|
|
78
|
+
...includeQuery(includeFields),
|
|
58
79
|
})
|
|
59
80
|
.strict();
|
|
60
81
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/json-api-nestjs",
|
|
3
3
|
"description": "Utilities for adhering to the JSON:API specification with NestJS.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "2.7.0",
|
|
7
7
|
"zod": "3.23.8"
|
|
8
8
|
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"type-fest": "4.26.1"
|
|
11
|
+
},
|
|
9
12
|
"keywords": [],
|
|
10
13
|
"license": "MIT",
|
|
11
14
|
"main": "./src/index.js",
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./lib/query/
|
|
2
|
-
export * from "./lib/query/
|
|
3
|
-
export * from "./lib/query/
|
|
4
|
-
export * from "./lib/query/
|
|
5
|
-
export * from "./lib/query/
|
|
1
|
+
export * from "./lib/query/cursorPaginationQuery";
|
|
2
|
+
export * from "./lib/query/fieldsQuery";
|
|
3
|
+
export * from "./lib/query/filterQuery";
|
|
4
|
+
export * from "./lib/query/includeQuery";
|
|
5
|
+
export * from "./lib/query/sortQuery";
|
|
6
6
|
export * from "./lib/schemas";
|
|
7
7
|
export * from "./lib/types";
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/query/
|
|
5
|
-
tslib_1.__exportStar(require("./lib/query/
|
|
6
|
-
tslib_1.__exportStar(require("./lib/query/
|
|
7
|
-
tslib_1.__exportStar(require("./lib/query/
|
|
8
|
-
tslib_1.__exportStar(require("./lib/query/
|
|
4
|
+
tslib_1.__exportStar(require("./lib/query/cursorPaginationQuery"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/query/fieldsQuery"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/query/filterQuery"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/query/includeQuery"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/query/sortQuery"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./lib/schemas"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./lib/types"), exports);
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/json-api-nestjs/src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/json-api-nestjs/src/index.ts"],"names":[],"mappings":";;;AAAA,4EAAkD;AAClD,kEAAwC;AACxC,kEAAwC;AACxC,mEAAyC;AACzC,gEAAsC;AACtC,wDAA8B;AAC9B,sDAA4B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryFilterPreprocessor = queryFilterPreprocessor;
|
|
2
4
|
/**
|
|
3
5
|
* NestJS-specific query processing based on the output of `ctx.switchToHttp().getRequest().query`.
|
|
4
6
|
*
|
|
@@ -12,8 +14,6 @@
|
|
|
12
14
|
* 5. For `?filter[age][gt]=5&filter[age]=10&filter[age]=20`, `value` is `{'0': '10', '1': '20', gt:
|
|
13
15
|
* '5'}`, which we transform to `{eq: "10,20", gt: "5"}`.
|
|
14
16
|
*/
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.queryFilterPreprocessor = queryFilterPreprocessor;
|
|
17
17
|
function queryFilterPreprocessor(value) {
|
|
18
18
|
if (!isObject(value)) {
|
|
19
19
|
// Cases 1 and 2.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryFilterPreprocessor.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/internal/queryFilterPreprocessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queryFilterPreprocessor.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/internal/queryFilterPreprocessor.ts"],"names":[],"mappings":";;AAaA,0DAwBC;AArCD;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB,CAAC,KAAc;IACpD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,iBAAiB;QACjB,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAyB,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACnF,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,SAAS,CAAC;QAC7C,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;YACnC,iBAAiB;YACjB,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO;gBACL,GAAG,MAAM;gBACT,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;aAChD,CAAC;QACJ,CAAC;QAED,+CAA+C;QAC/C,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO;YACL,GAAG,MAAM;YACT,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW;SACnE,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,uDAAuD;IACvD,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export declare const PAGINATION: {
|
|
3
|
+
readonly size: {
|
|
4
|
+
readonly maximum: 200;
|
|
5
|
+
readonly default: 20;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Creates a Zod schema for JSON:API cursor pagination.
|
|
4
10
|
*
|
|
@@ -8,9 +14,11 @@ import { z } from "zod";
|
|
|
8
14
|
* @see {@link https://jsonapi.org/format/#fetching-pagination JSON:API pagination}
|
|
9
15
|
* @see {@link https://jsonapi.org/examples/#pagination JSON:API pagination examples}
|
|
10
16
|
*/
|
|
11
|
-
export declare function
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
export declare function cursorPaginationQuery(parameters?: Readonly<{
|
|
18
|
+
size: {
|
|
19
|
+
maximum?: number;
|
|
20
|
+
default?: number;
|
|
21
|
+
};
|
|
14
22
|
}>): {
|
|
15
23
|
page: z.ZodDefault<z.ZodObject<{
|
|
16
24
|
size: z.ZodDefault<z.ZodNumber>;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PAGINATION = void 0;
|
|
4
|
+
exports.cursorPaginationQuery = cursorPaginationQuery;
|
|
4
5
|
const zod_1 = require("zod");
|
|
5
6
|
const schemas_1 = require("../schemas");
|
|
7
|
+
exports.PAGINATION = {
|
|
8
|
+
size: {
|
|
9
|
+
maximum: 200,
|
|
10
|
+
default: 20,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
6
13
|
/**
|
|
7
14
|
* Creates a Zod schema for JSON:API cursor pagination.
|
|
8
15
|
*
|
|
@@ -12,16 +19,17 @@ const schemas_1 = require("../schemas");
|
|
|
12
19
|
* @see {@link https://jsonapi.org/format/#fetching-pagination JSON:API pagination}
|
|
13
20
|
* @see {@link https://jsonapi.org/examples/#pagination JSON:API pagination examples}
|
|
14
21
|
*/
|
|
15
|
-
function
|
|
16
|
-
const {
|
|
22
|
+
function cursorPaginationQuery(parameters) {
|
|
23
|
+
const { size } = exports.PAGINATION;
|
|
24
|
+
const { maximum = size.maximum, default: defaultSize = size.default } = parameters?.size ?? {};
|
|
17
25
|
return {
|
|
18
26
|
page: zod_1.z
|
|
19
27
|
.object({
|
|
20
|
-
size: zod_1.z.coerce.number().int().positive().max(
|
|
28
|
+
size: zod_1.z.coerce.number().int().positive().max(maximum).default(defaultSize),
|
|
21
29
|
cursor: schemas_1.nonEmptyString.optional(),
|
|
22
30
|
})
|
|
23
31
|
.strict()
|
|
24
32
|
.default({ size: defaultSize }),
|
|
25
33
|
};
|
|
26
34
|
}
|
|
27
|
-
//# sourceMappingURL=
|
|
35
|
+
//# sourceMappingURL=cursorPaginationQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursorPaginationQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/cursorPaginationQuery.ts"],"names":[],"mappings":";;;AAoBA,sDAeC;AAnCD,6BAAwB;AAExB,wCAA4C;AAE/B,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE;QACJ,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,EAAE;KACZ;CACO,CAAC;AAEX;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,UAAuE;IAEvE,MAAM,EAAE,IAAI,EAAE,GAAG,kBAAU,CAAC;IAC5B,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC;IAE/F,OAAO;QACL,IAAI,EAAE,OAAC;aACJ,MAAM,CAAC;YACN,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;YAC1E,MAAM,EAAE,wBAAc,CAAC,QAAQ,EAAE;SAClC,CAAC;aACD,MAAM,EAAE;aACR,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type ApiType, type Field } from "../types";
|
|
2
|
+
import { type ApiType, type Data, type Field, type JsonApiDocument } from "../types";
|
|
3
3
|
export type FieldsMap = Record<ApiType, readonly [Field, ...Field[]]>;
|
|
4
4
|
export type FieldsSchema<MapT extends FieldsMap> = {
|
|
5
5
|
[K in keyof MapT]: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEnum<z.Writeable<MapT[K]>>>>, Array<MapT[K][number]> | undefined, unknown>;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* JSON:API attribute fields for use in fields queries.
|
|
9
|
+
*
|
|
10
|
+
* @template DocumentT - The JSON:API document.
|
|
11
|
+
*/
|
|
12
|
+
export type AttributeFields<DocumentT extends JsonApiDocument> = DocumentT["data"] extends Array<infer R extends Data> ? keyof R["attributes"] : DocumentT["data"] extends Data ? keyof DocumentT["data"]["attributes"] : never;
|
|
7
13
|
/**
|
|
8
14
|
* Creates a Zod schema for JSON:API sparse fieldsets.
|
|
9
15
|
*
|
|
@@ -12,6 +18,6 @@ export type FieldsSchema<MapT extends FieldsMap> = {
|
|
|
12
18
|
* @see [Usage example](../../../examples/query.ts)
|
|
13
19
|
* @see {@link https://jsonapi.org/format/#fetching-sparse-fieldsets JSON:API sparse fieldsets}
|
|
14
20
|
*/
|
|
15
|
-
export declare function
|
|
21
|
+
export declare function fieldsQuery<const MapT extends FieldsMap>(parameters: Readonly<MapT>): {
|
|
16
22
|
fields: z.ZodOptional<z.ZodObject<FieldsSchema<MapT>, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FieldsSchema<MapT>>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FieldsSchema<MapT>>, any>[k]; } : never, z.baseObjectInputType<FieldsSchema<MapT>> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<FieldsSchema<MapT>>[k_1]; } : never>>;
|
|
17
23
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fieldsQuery = fieldsQuery;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const splitString_1 = require("../internal/splitString");
|
|
6
6
|
/**
|
|
@@ -11,13 +11,13 @@ const splitString_1 = require("../internal/splitString");
|
|
|
11
11
|
* @see [Usage example](../../../examples/query.ts)
|
|
12
12
|
* @see {@link https://jsonapi.org/format/#fetching-sparse-fieldsets JSON:API sparse fieldsets}
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function fieldsQuery(parameters) {
|
|
15
15
|
const fieldSchemas = Object.fromEntries(Object.entries(parameters).map(([apiType, fields]) => [
|
|
16
16
|
apiType,
|
|
17
|
-
zod_1.z.preprocess(splitString_1.splitString, zod_1.z.
|
|
17
|
+
zod_1.z.preprocess(splitString_1.splitString, zod_1.z.enum(fields).array().min(1).max(100).optional()),
|
|
18
18
|
]));
|
|
19
19
|
return {
|
|
20
20
|
fields: zod_1.z.object(fieldSchemas).strict().optional(),
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
//# sourceMappingURL=
|
|
23
|
+
//# sourceMappingURL=fieldsQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldsQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/fieldsQuery.ts"],"names":[],"mappings":";;AAmCA,kCAYC;AA/CD,6BAAwB;AAExB,yDAAsD;AAyBtD;;;;;;;GAOG;AACH,SAAgB,WAAW,CAA+B,UAA0B;IAClF,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CACrC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAiC,EAAE,EAAE,CAAC;QACpF,OAAO;QACP,OAAC,CAAC,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;KAC7E,CAAC,CAEmB,CAAC;IAExB,OAAO;QACL,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACnD,CAAC;AACJ,CAAC"}
|
|
@@ -19,6 +19,6 @@ export type FilterSchema<MapT extends FilterMap> = {
|
|
|
19
19
|
* @see {@link https://jsonapi.org/recommendations/#filtering JSON:API filtering}
|
|
20
20
|
* @see {@link https://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257 JSON:API filtering strategy}
|
|
21
21
|
*/
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function filterQuery<const MapT extends FilterMap>(parameters: Readonly<MapT>): {
|
|
23
23
|
filter: z.ZodOptional<z.ZodObject<FilterSchema<MapT>, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FilterSchema<MapT>>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FilterSchema<MapT>>, any>[k]; } : never, z.baseObjectInputType<FilterSchema<MapT>> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<FilterSchema<MapT>>[k_1]; } : never>>;
|
|
24
24
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filterQuery = filterQuery;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const queryFilterPreprocessor_1 = require("../internal/queryFilterPreprocessor");
|
|
6
6
|
const splitString_1 = require("../internal/splitString");
|
|
@@ -13,7 +13,7 @@ const splitString_1 = require("../internal/splitString");
|
|
|
13
13
|
* @see {@link https://jsonapi.org/recommendations/#filtering JSON:API filtering}
|
|
14
14
|
* @see {@link https://discuss.jsonapi.org/t/share-propose-a-filtering-strategy/257 JSON:API filtering strategy}
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function filterQuery(parameters) {
|
|
17
17
|
return {
|
|
18
18
|
filter: zod_1.z
|
|
19
19
|
.object(Object.fromEntries(Object.entries(parameters).map(([apiType, { filters, schema }]) => [
|
|
@@ -22,7 +22,9 @@ function createFilter(parameters) {
|
|
|
22
22
|
.preprocess(queryFilterPreprocessor_1.queryFilterPreprocessor, zod_1.z
|
|
23
23
|
.object(Object.fromEntries(filters.map((filter) => [
|
|
24
24
|
filter,
|
|
25
|
-
zod_1.z
|
|
25
|
+
zod_1.z
|
|
26
|
+
.preprocess(splitString_1.splitString, schema.array().min(1).max(10_000).optional())
|
|
27
|
+
.optional(),
|
|
26
28
|
])))
|
|
27
29
|
.strict()
|
|
28
30
|
.optional())
|
|
@@ -32,4 +34,4 @@ function createFilter(parameters) {
|
|
|
32
34
|
.optional(),
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=filterQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/filterQuery.ts"],"names":[],"mappings":";;AAuCA,kCAkCC;AAzED,6BAAwB;AAExB,iFAA8E;AAC9E,yDAAsD;AA2BtD;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAA+B,UAA0B;IAClF,OAAO;QACL,MAAM,EAAE,OAAC;aACN,MAAM,CACL,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAC5B,CAAC,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAiC,EAAE,EAAE,CAAC;YAClE,OAAO;YACP,OAAC;iBACE,UAAU,CACT,iDAAuB,EACvB,OAAC;iBACE,MAAM,CACL,MAAM,CAAC,WAAW,CAChB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC;gBAC9B,MAAM;gBACN,OAAC;qBACE,UAAU,CAAC,yBAAW,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;qBACrE,QAAQ,EAAE;aACd,CAAC,CACH,CACF;iBACA,MAAM,EAAE;iBACR,QAAQ,EAAE,CACd;iBACA,QAAQ,EAAE;SACd,CACF,CAEoB,CACxB;aACA,MAAM,EAAE;aACR,QAAQ,EAAE;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type GreaterThan, type Subtract } from "type-fest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type JsonApiDocument, type Relationship } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* JSON:API relationship paths for use in include queries.
|
|
6
|
+
*
|
|
7
|
+
* @template MapT - A map of ApiType to Zod schemas.
|
|
8
|
+
* @template DocumentT - The JSON:API document.
|
|
9
|
+
* @template RecursiveDepth - The maximum depth for recursive relationship traversal.
|
|
10
|
+
* @template Prefix - The prefix for nested relationship paths.
|
|
11
|
+
*/
|
|
12
|
+
export type RelationshipPaths<MapT extends Record<string, z.ZodTypeAny>, DocumentT extends JsonApiDocument, RecursiveDepth extends number = 5, Prefix extends string = ""> = RecursiveDepth extends infer Depth extends number ? GreaterThan<Depth, 0> extends true ? DocumentT["data"] extends Array<infer SingleOrArray> | infer SingleOrArray ? SingleOrArray extends {
|
|
13
|
+
relationships?: infer R;
|
|
14
|
+
} ? R extends Record<string, Relationship> ? {
|
|
15
|
+
[K in keyof R]: K extends string ? R[K]["data"] extends {
|
|
16
|
+
type?: infer RelationT;
|
|
17
|
+
} | Array<{
|
|
18
|
+
type?: infer RelationT;
|
|
19
|
+
}> ? RelationT extends keyof MapT ? `${Prefix}${K}` | RelationshipPaths<MapT, z.infer<MapT[RelationT]>, Subtract<Depth, 1>, `${Prefix}${K}.`> : never : never : never;
|
|
20
|
+
}[keyof R] : never : never : never : never : never;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a Zod schema for JSON:API include parameters.
|
|
23
|
+
*
|
|
24
|
+
* @includeExample ./packages/json-api-nestjs/examples/query.ts
|
|
25
|
+
*
|
|
26
|
+
* @see [Usage example](../../../examples/query.ts)
|
|
27
|
+
* @see {@link https://jsonapi.org/format/#fetching-includes JSON:API includes}
|
|
28
|
+
*/
|
|
29
|
+
export declare function includeQuery<const FieldT extends readonly string[]>(fields: FieldT): {
|
|
30
|
+
include: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodString, "many">>, string[] | undefined, unknown>, string[] | undefined, unknown>, FieldT[number][] | undefined, unknown>;
|
|
31
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.includeQuery = includeQuery;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const splitString_1 = require("../internal/splitString");
|
|
6
6
|
/**
|
|
7
7
|
* Creates a Zod schema for JSON:API include parameters.
|
|
8
8
|
*
|
|
9
|
-
* @
|
|
10
|
-
* @returns A Zod schema for the include parameter.
|
|
9
|
+
* @includeExample ./packages/json-api-nestjs/examples/query.ts
|
|
11
10
|
*
|
|
11
|
+
* @see [Usage example](../../../examples/query.ts)
|
|
12
12
|
* @see {@link https://jsonapi.org/format/#fetching-includes JSON:API includes}
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function includeQuery(fields) {
|
|
15
15
|
const fieldSet = new Set(fields);
|
|
16
16
|
return {
|
|
17
17
|
include: zod_1.z
|
|
18
|
-
.preprocess(splitString_1.splitString, zod_1.z.array(
|
|
18
|
+
.preprocess(splitString_1.splitString, zod_1.z.string().array().min(1).max(100).optional())
|
|
19
19
|
.superRefine((value, context) => {
|
|
20
20
|
if (!value) {
|
|
21
21
|
return;
|
|
@@ -33,4 +33,4 @@ function createInclude(fields) {
|
|
|
33
33
|
.transform((value) => value),
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=includeQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includeQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/includeQuery.ts"],"names":[],"mappings":";;AAwDA,oCAuBC;AA9ED,6BAAwB;AAExB,yDAAsD;AA6CtD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAyC,MAAc;IACjF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO;QACL,OAAO,EAAE,OAAC;aACP,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;aACtE,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,OAAO,CAAC,QAAQ,CAAC;wBACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,2BAA2B,KAAK,GAAG;wBAC5C,IAAI,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC;qBACzB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAA0C,CAAC;KACpE,CAAC;AACJ,CAAC"}
|
|
@@ -8,6 +8,6 @@ import { type Field } from "../types";
|
|
|
8
8
|
* @see [Usage example](../../../examples/query.ts)
|
|
9
9
|
* @see {@link https://jsonapi.org/format/#fetching-sorting JSON:API sorting}
|
|
10
10
|
*/
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function sortQuery<const FieldT extends readonly [Field, ...Field[]]>(fields: FieldT): {
|
|
12
12
|
sort: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodString, "many">>, string[] | undefined, unknown>, string[] | undefined, unknown>, (FieldT[number] | `-${FieldT[number]}`)[] | undefined, unknown>;
|
|
13
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.sortQuery = sortQuery;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const splitString_1 = require("../internal/splitString");
|
|
6
6
|
/**
|
|
@@ -11,11 +11,11 @@ const splitString_1 = require("../internal/splitString");
|
|
|
11
11
|
* @see [Usage example](../../../examples/query.ts)
|
|
12
12
|
* @see {@link https://jsonapi.org/format/#fetching-sorting JSON:API sorting}
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function sortQuery(fields) {
|
|
15
15
|
const fieldSet = new Set(fields);
|
|
16
16
|
return {
|
|
17
17
|
sort: zod_1.z
|
|
18
|
-
.preprocess(splitString_1.splitString, zod_1.z.array(
|
|
18
|
+
.preprocess(splitString_1.splitString, zod_1.z.string().array().min(1).max(100).optional())
|
|
19
19
|
.superRefine((value, context) => {
|
|
20
20
|
if (!value) {
|
|
21
21
|
return;
|
|
@@ -33,4 +33,4 @@ function createSort(fields) {
|
|
|
33
33
|
.transform((value) => value),
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=sortQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortQuery.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/sortQuery.ts"],"names":[],"mappings":";;AAaA,8BAsBC;AAnCD,6BAAwB;AAExB,yDAAsD;AAGtD;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAoD,MAAc;IACzF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO;QACL,IAAI,EAAE,OAAC;aACJ,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;aACtE,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClE,OAAO,CAAC,QAAQ,CAAC;wBACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,wBAAwB,KAAK,GAAG;wBACzC,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;qBACtB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAiE,CAAC;KAC3F,CAAC;AACJ,CAAC"}
|
package/src/lib/types.d.ts
CHANGED
|
@@ -1,2 +1,36 @@
|
|
|
1
|
+
import { type Arrayable } from "type-fest";
|
|
1
2
|
export type ApiType = string;
|
|
2
3
|
export type Field = string;
|
|
4
|
+
export type Meta = Record<string, unknown>;
|
|
5
|
+
export type ApiLinks = Record<string, string | undefined>;
|
|
6
|
+
export interface Relationship {
|
|
7
|
+
data: Arrayable<{
|
|
8
|
+
id: string;
|
|
9
|
+
type: ApiType;
|
|
10
|
+
}>;
|
|
11
|
+
links?: ApiLinks;
|
|
12
|
+
meta?: Meta;
|
|
13
|
+
}
|
|
14
|
+
export interface Data {
|
|
15
|
+
attributes: Record<string, unknown>;
|
|
16
|
+
id: string;
|
|
17
|
+
links?: ApiLinks;
|
|
18
|
+
meta?: Meta;
|
|
19
|
+
relationships?: Record<string, Relationship>;
|
|
20
|
+
type: ApiType;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The JSON:API document shape.
|
|
24
|
+
*/
|
|
25
|
+
export interface JsonApiDocument {
|
|
26
|
+
data: Arrayable<Data>;
|
|
27
|
+
included?: Data[];
|
|
28
|
+
jsonapi?: {
|
|
29
|
+
ext?: Record<string, unknown>;
|
|
30
|
+
meta?: Meta;
|
|
31
|
+
profile?: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
};
|
|
34
|
+
links?: ApiLinks;
|
|
35
|
+
meta?: Meta;
|
|
36
|
+
}
|
package/src/test/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { type SafeParseError, type SafeParseReturnType, type SafeParseSuccess } from "zod";
|
|
2
|
-
export declare function expectToBeDefined<T>(value: T | undefined): asserts value is T;
|
|
3
2
|
export declare function expectToBeSuccess<Input, Output>(value: Readonly<SafeParseReturnType<Input, Output>>): asserts value is SafeParseSuccess<Output>;
|
|
4
3
|
export declare function expectToBeError<Input, Output>(value: Readonly<SafeParseReturnType<Input, Output>>): asserts value is SafeParseError<Input>;
|
package/src/test/index.js
CHANGED
package/src/test/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/json-api-nestjs/src/test/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/json-api-nestjs/src/test/index.ts"],"names":[],"mappings":";;AAmBA,8CAKC;AAED,0CAKC;AA/BD,6CAAiC;AAOjC,SAAS,iBAAiB,CAAI,KAA0B;IACtD,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC;AAED,SAAS,SAAS,CAAI,KAA0B;IAC9C,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,iBAAiB,CAAI,KAAoB;IAChD,IAAA,gBAAE,EAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,SAAgB,iBAAiB,CAC/B,KAAmD;IAEnD,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,IAAA,gBAAE,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACpB,CAAC;AAED,SAAgB,eAAe,CAC7B,KAAmD;IAEnD,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,IAAA,gBAAE,EAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createCursorPagination.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createCursorPagination.ts"],"names":[],"mappings":";;AAaA,wDAcC;AA3BD,6BAAwB;AAExB,wCAA4C;AAE5C;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CACpC,UAAqE;IAErE,MAAM,EAAE,WAAW,GAAG,GAAG,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;IAEjE,OAAO;QACL,IAAI,EAAE,OAAC;aACJ,MAAM,CAAC;YACN,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;YAC9E,MAAM,EAAE,wBAAc,CAAC,QAAQ,EAAE;SAClC,CAAC;aACD,MAAM,EAAE;aACR,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFields.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createFields.ts"],"names":[],"mappings":";;AAuBA,oCAYC;AAnCD,6BAAwB;AAExB,yDAAsD;AAatD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAA+B,UAA0B;IACnF,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CACrC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAiC,EAAE,EAAE,CAAC;QACpF,OAAO;QACP,OAAC,CAAC,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;KACrE,CAAC,CAEmB,CAAC;IAExB,OAAO;QACL,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACnD,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFilter.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createFilter.ts"],"names":[],"mappings":";;AAuCA,oCAgCC;AAvED,6BAAwB;AAExB,iFAA8E;AAC9E,yDAAsD;AA2BtD;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAA+B,UAA0B;IACnF,OAAO;QACL,MAAM,EAAE,OAAC;aACN,MAAM,CACL,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAC5B,CAAC,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAiC,EAAE,EAAE,CAAC;YAClE,OAAO;YACP,OAAC;iBACE,UAAU,CACT,iDAAuB,EACvB,OAAC;iBACE,MAAM,CACL,MAAM,CAAC,WAAW,CAChB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC;gBAC9B,MAAM;gBACN,OAAC,CAAC,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE;aACjE,CAAC,CACH,CACF;iBACA,MAAM,EAAE;iBACR,QAAQ,EAAE,CACd;iBACA,QAAQ,EAAE;SACd,CACF,CAEoB,CACxB;aACA,MAAM,EAAE;aACR,QAAQ,EAAE;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a Zod schema for JSON:API include parameters.
|
|
4
|
-
*
|
|
5
|
-
* @param fields An array of valid include fields.
|
|
6
|
-
* @returns A Zod schema for the include parameter.
|
|
7
|
-
*
|
|
8
|
-
* @see {@link https://jsonapi.org/format/#fetching-includes JSON:API includes}
|
|
9
|
-
*/
|
|
10
|
-
export declare function createInclude<const FieldT extends readonly string[]>(fields: FieldT): {
|
|
11
|
-
include: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodString, "many">>, string[] | undefined, unknown>, string[] | undefined, unknown>, FieldT[number][] | undefined, unknown>;
|
|
12
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createInclude.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createInclude.ts"],"names":[],"mappings":";;AAYA,sCAuBC;AAnCD,6BAAwB;AAExB,yDAAsD;AAEtD;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAyC,MAAc;IAClF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO;QACL,OAAO,EAAE,OAAC;aACP,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;aACvD,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,OAAO,CAAC,QAAQ,CAAC;wBACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,2BAA2B,KAAK,GAAG;wBAC5C,IAAI,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC;qBACzB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAA0C,CAAC;KACpE,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSort.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createSort.ts"],"names":[],"mappings":";;AAaA,gCAsBC;AAnCD,6BAAwB;AAExB,yDAAsD;AAGtD;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAoD,MAAc;IAC1F,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO;QACL,IAAI,EAAE,OAAC;aACJ,UAAU,CAAC,yBAAW,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;aACvD,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClE,OAAO,CAAC,QAAQ,CAAC;wBACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;wBAC3B,OAAO,EAAE,wBAAwB,KAAK,GAAG;wBACzC,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;qBACtB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAiE,CAAC;KAC3F,CAAC;AACJ,CAAC"}
|