@clipboard-health/json-api-nestjs 0.1.0
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 +31 -0
- package/package.json +18 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/lib/internal/queryFilterPreprocessor.d.ts +14 -0
- package/src/lib/internal/queryFilterPreprocessor.js +44 -0
- package/src/lib/internal/queryFilterPreprocessor.js.map +1 -0
- package/src/lib/internal/splitString.d.ts +1 -0
- package/src/lib/internal/splitString.js +7 -0
- package/src/lib/internal/splitString.js.map +1 -0
- package/src/lib/query/createCursorPagination.d.ts +16 -0
- package/src/lib/query/createCursorPagination.js +18 -0
- package/src/lib/query/createCursorPagination.js.map +1 -0
- package/src/lib/query/createFields.d.ts +11 -0
- package/src/lib/query/createFields.js +15 -0
- package/src/lib/query/createFields.js.map +1 -0
- package/src/lib/query/createFilter.d.ts +15 -0
- package/src/lib/query/createFilter.js +26 -0
- package/src/lib/query/createFilter.js.map +1 -0
- package/src/lib/schemas.d.ts +3 -0
- package/src/lib/schemas.js +7 -0
- package/src/lib/schemas.js.map +1 -0
- package/src/lib/types.d.ts +1 -0
- package/src/lib/types.js +3 -0
- package/src/lib/types.js.map +1 -0
- package/src/test/index.d.ts +4 -0
- package/src/test/index.js +24 -0
- package/src/test/index.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @clipboard-health/json-api-nestjs
|
|
2
|
+
|
|
3
|
+
Utilities for adhering to the [JSON:API](https://jsonapi.org/) specification with [NestJS](https://nestjs.com/).
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Install](#install)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Query helpers](#query-helpers)
|
|
10
|
+
- [Local development commands](#local-development-commands)
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @clipboard-health/json-api-nestjs
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Query helpers
|
|
21
|
+
|
|
22
|
+
Create Zod schemas for your API's queries:
|
|
23
|
+
|
|
24
|
+
<!-- prettier-ignore -->
|
|
25
|
+
```ts
|
|
26
|
+
// ./examples/query.ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Local development commands
|
|
30
|
+
|
|
31
|
+
See [`package.json`](./package.json) `scripts` for a list of commands.
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clipboard-health/json-api-nestjs",
|
|
3
|
+
"description": "Utilities for adhering to the JSON:API specification with NestJS.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"tslib": "2.7.0",
|
|
7
|
+
"zod": "3.23.8"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "./src/index.js",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "restricted"
|
|
14
|
+
},
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"typings": "./src/index.d.ts",
|
|
17
|
+
"types": "./src/index.d.ts"
|
|
18
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/query/createCursorPagination"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/query/createFields"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/query/createFilter"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/schemas"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/json-api-nestjs/src/index.ts"],"names":[],"mappings":";;;AAAA,6EAAmD;AACnD,mEAAyC;AACzC,mEAAyC;AACzC,wDAA8B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NestJS-specific query processing based on the output of `ctx.switchToHttp().getRequest().query`.
|
|
3
|
+
*
|
|
4
|
+
* We handle the following cases:
|
|
5
|
+
* 1. For `?filter[age]=10,20`, `value` is `10,20`, which we transform to `{eq: "10,20"}`.
|
|
6
|
+
* 2. For `?filter[age]=20`, `value` is `20`, which we transform to `{eq: "20"}`.
|
|
7
|
+
* 3. For `?filter[age][gt]=10&filter[age]=20`, `value` is `{'20': true, gt: '10'}`, which we
|
|
8
|
+
* transform to `{eq: "20", gt: "10"}`.
|
|
9
|
+
* 4. For `?filter[age]=10&filter[age]=20`, `value` is `['10', '20']`, which we transform to `{eq:
|
|
10
|
+
* "10,20"}`.
|
|
11
|
+
* 5. For `?filter[age][gt]=5&filter[age]=10&filter[age]=20`, `value` is `{'0': '10', '1': '20', gt:
|
|
12
|
+
* '5'}`, which we transform to `{eq: "10,20", gt: "5"}`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function queryFilterPreprocessor(value: unknown): Record<string, string>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NestJS-specific query processing based on the output of `ctx.switchToHttp().getRequest().query`.
|
|
4
|
+
*
|
|
5
|
+
* We handle the following cases:
|
|
6
|
+
* 1. For `?filter[age]=10,20`, `value` is `10,20`, which we transform to `{eq: "10,20"}`.
|
|
7
|
+
* 2. For `?filter[age]=20`, `value` is `20`, which we transform to `{eq: "20"}`.
|
|
8
|
+
* 3. For `?filter[age][gt]=10&filter[age]=20`, `value` is `{'20': true, gt: '10'}`, which we
|
|
9
|
+
* transform to `{eq: "20", gt: "10"}`.
|
|
10
|
+
* 4. For `?filter[age]=10&filter[age]=20`, `value` is `['10', '20']`, which we transform to `{eq:
|
|
11
|
+
* "10,20"}`.
|
|
12
|
+
* 5. For `?filter[age][gt]=5&filter[age]=10&filter[age]=20`, `value` is `{'0': '10', '1': '20', gt:
|
|
13
|
+
* '5'}`, which we transform to `{eq: "10,20", gt: "5"}`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.queryFilterPreprocessor = queryFilterPreprocessor;
|
|
17
|
+
function queryFilterPreprocessor(value) {
|
|
18
|
+
if (!isObject(value)) {
|
|
19
|
+
// Cases 1 and 2.
|
|
20
|
+
return { eq: String(value) };
|
|
21
|
+
}
|
|
22
|
+
return Object.entries(value).reduce((filter, [key, value]) => {
|
|
23
|
+
const boolValue = typeof value === "boolean";
|
|
24
|
+
if (/^\d+$/.test(key) || boolValue) {
|
|
25
|
+
// Cases 3 and 5.
|
|
26
|
+
const eq = boolValue ? key : String(value);
|
|
27
|
+
return {
|
|
28
|
+
...filter,
|
|
29
|
+
eq: filter["eq"] ? `${filter["eq"]},${eq}` : eq,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Case 4 and other cases like `gt`, `lt`, etc.
|
|
33
|
+
const stringValue = Array.isArray(value) ? value.join(",") : String(value);
|
|
34
|
+
return {
|
|
35
|
+
...filter,
|
|
36
|
+
[key]: filter[key] ? `${filter[key]},${stringValue}` : stringValue,
|
|
37
|
+
};
|
|
38
|
+
}, {});
|
|
39
|
+
}
|
|
40
|
+
function isObject(value) {
|
|
41
|
+
// eslint-disable-next-line no-eq-null, unicorn/no-null
|
|
42
|
+
return value != null && typeof value === "object";
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=queryFilterPreprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryFilterPreprocessor.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/internal/queryFilterPreprocessor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAEH,0DAwBC;AAxBD,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function splitString(value: unknown): unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitString.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/internal/splitString.ts"],"names":[],"mappings":";;AAAA,kCAEC;AAFD,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare function createCursorPagination(parameters?: Readonly<{
|
|
3
|
+
maximumSize?: number;
|
|
4
|
+
defaultSize?: number;
|
|
5
|
+
}>): {
|
|
6
|
+
page: z.ZodDefault<z.ZodObject<{
|
|
7
|
+
size: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strict", z.ZodTypeAny, {
|
|
10
|
+
size: number;
|
|
11
|
+
cursor?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
size?: number | undefined;
|
|
14
|
+
cursor?: string | undefined;
|
|
15
|
+
}>>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCursorPagination = createCursorPagination;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schemas_1 = require("../schemas");
|
|
6
|
+
function createCursorPagination(parameters) {
|
|
7
|
+
const { maximumSize = 200, defaultSize = 20 } = parameters ?? {};
|
|
8
|
+
return {
|
|
9
|
+
page: zod_1.z
|
|
10
|
+
.object({
|
|
11
|
+
size: zod_1.z.coerce.number().int().positive().max(maximumSize).default(defaultSize),
|
|
12
|
+
cursor: schemas_1.nonEmptyString.optional(),
|
|
13
|
+
})
|
|
14
|
+
.strict()
|
|
15
|
+
.default({ size: defaultSize }),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=createCursorPagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCursorPagination.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createCursorPagination.ts"],"names":[],"mappings":";;AAIA,wDAcC;AAlBD,6BAAwB;AAExB,wCAA4C;AAE5C,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ApiType } from "../types";
|
|
3
|
+
type Field = string;
|
|
4
|
+
export type FieldsMap = Record<ApiType, readonly [Field, ...Field[]]>;
|
|
5
|
+
export type FieldsSchema<MapT extends FieldsMap> = {
|
|
6
|
+
[K in keyof MapT]: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEnum<z.Writeable<MapT[K]>>>>, Array<MapT[K][number]> | undefined, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export declare function createFields<const MapT extends FieldsMap>(parameters: Readonly<MapT>): {
|
|
9
|
+
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>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFields = createFields;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const splitString_1 = require("../internal/splitString");
|
|
6
|
+
function createFields(parameters) {
|
|
7
|
+
const fieldSchemas = Object.fromEntries(Object.entries(parameters).map(([apiType, fields]) => [
|
|
8
|
+
apiType,
|
|
9
|
+
zod_1.z.preprocess(splitString_1.splitString, zod_1.z.array(zod_1.z.enum(fields)).min(1).optional()),
|
|
10
|
+
]));
|
|
11
|
+
return {
|
|
12
|
+
fields: zod_1.z.object(fieldSchemas).strict().optional(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=createFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFields.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createFields.ts"],"names":[],"mappings":";;AAiBA,oCAYC;AA7BD,6BAAwB;AAExB,yDAAsD;AAetD,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ApiType } from "../types";
|
|
3
|
+
export type Filter = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "not";
|
|
4
|
+
export type FilterMap = Record<ApiType, {
|
|
5
|
+
filters: readonly [Filter, ...Filter[]];
|
|
6
|
+
schema: z.ZodTypeAny;
|
|
7
|
+
}>;
|
|
8
|
+
export type FilterObject<MapT extends FilterMap> = {
|
|
9
|
+
[K in keyof MapT]: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
|
|
10
|
+
[F in MapT[K]["filters"][number]]: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodArray<MapT[K]["schema"]>>>>;
|
|
11
|
+
}>>>>;
|
|
12
|
+
};
|
|
13
|
+
export declare function createFilter<const MapT extends FilterMap>(parameters: Readonly<MapT>): {
|
|
14
|
+
filter: z.ZodOptional<z.ZodObject<FilterObject<MapT>, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FilterObject<MapT>>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<FilterObject<MapT>>, any>[k]; } : never, z.baseObjectInputType<FilterObject<MapT>> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<FilterObject<MapT>>[k_1]; } : never>>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilter = createFilter;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const queryFilterPreprocessor_1 = require("../internal/queryFilterPreprocessor");
|
|
6
|
+
const splitString_1 = require("../internal/splitString");
|
|
7
|
+
function createFilter(parameters) {
|
|
8
|
+
return {
|
|
9
|
+
filter: zod_1.z
|
|
10
|
+
.object(Object.fromEntries(Object.entries(parameters).map(([apiType, { filters, schema }]) => [
|
|
11
|
+
apiType,
|
|
12
|
+
zod_1.z
|
|
13
|
+
.preprocess(queryFilterPreprocessor_1.queryFilterPreprocessor, zod_1.z
|
|
14
|
+
.object(Object.fromEntries(filters.map((filter) => [
|
|
15
|
+
filter,
|
|
16
|
+
zod_1.z.preprocess(splitString_1.splitString, zod_1.z.array(schema).optional()).optional(),
|
|
17
|
+
])))
|
|
18
|
+
.strict()
|
|
19
|
+
.optional())
|
|
20
|
+
.optional(),
|
|
21
|
+
])))
|
|
22
|
+
.strict()
|
|
23
|
+
.optional(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=createFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFilter.js","sourceRoot":"","sources":["../../../../../../packages/json-api-nestjs/src/lib/query/createFilter.ts"],"names":[],"mappings":";;AA8BA,oCAgCC;AA9DD,6BAAwB;AAExB,iFAA8E;AAC9E,yDAAsD;AA2BtD,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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.booleanString = exports.nonEmptyString = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.nonEmptyString = zod_1.z.string().min(1);
|
|
6
|
+
exports.booleanString = zod_1.z.enum(["true", "false"]).transform((value) => value === "true");
|
|
7
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../../../packages/json-api-nestjs/src/lib/schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEnC,QAAA,aAAa,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ApiType = string;
|
package/src/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../packages/json-api-nestjs/src/lib/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SafeParseError, type SafeParseReturnType, type SafeParseSuccess } from "zod";
|
|
2
|
+
export declare function expectToBeDefined<T>(value: T | undefined): asserts value is T;
|
|
3
|
+
export declare function expectToBeSuccess<Input, Output>(value: Readonly<SafeParseReturnType<Input, Output>>): asserts value is SafeParseSuccess<Output>;
|
|
4
|
+
export declare function expectToBeError<Input, Output>(value: Readonly<SafeParseReturnType<Input, Output>>): asserts value is SafeParseError<Input>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectToBeDefined = expectToBeDefined;
|
|
4
|
+
exports.expectToBeSuccess = expectToBeSuccess;
|
|
5
|
+
exports.expectToBeError = expectToBeError;
|
|
6
|
+
const node_assert_1 = require("node:assert");
|
|
7
|
+
function isNullOrUndefined(value) {
|
|
8
|
+
return value === null || value === undefined;
|
|
9
|
+
}
|
|
10
|
+
function isDefined(value) {
|
|
11
|
+
return !isNullOrUndefined(value);
|
|
12
|
+
}
|
|
13
|
+
function expectToBeDefined(value) {
|
|
14
|
+
(0, node_assert_1.ok)(isDefined(value));
|
|
15
|
+
}
|
|
16
|
+
function expectToBeSuccess(value) {
|
|
17
|
+
expectToBeDefined(value);
|
|
18
|
+
(0, node_assert_1.ok)(value.success);
|
|
19
|
+
}
|
|
20
|
+
function expectToBeError(value) {
|
|
21
|
+
expectToBeDefined(value);
|
|
22
|
+
(0, node_assert_1.ok)(!value.success);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/json-api-nestjs/src/test/index.ts"],"names":[],"mappings":";;AAeA,8CAEC;AAED,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,SAAgB,iBAAiB,CAAI,KAAoB;IACvD,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"}
|