Skip to content

Commit 13a5a2b

Browse files
committed
feat: allow passing down additional context through relationships
1 parent 614b2d8 commit 13a5a2b

17 files changed

+857
-836
lines changed

.lefthook/commit-msg/commitlint.sh

-1
This file was deleted.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ serializeManager.createResourceDocument("my_entity", entity, {
7474
});
7575
```
7676

77+
Additionally, when you define a relationship in a serializer as an entity, you can pass down additional context which
78+
will be merged with the parent context.
79+
7780
#### Filtering
7881

7982
You can add filters to list handlers as well. JSON:API does not define the structure of filters itself, except that the

biome.json

+10-23
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.5.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
33
"organizeImports": {
44
"enabled": true
55
},
66
"files": {
7-
"include": [
8-
"biome.json",
9-
"commitlint.config.cjs",
10-
"release.config.cjs",
11-
"src/**/*",
12-
"test/**/*",
13-
"examples/*/src/**/*"
14-
]
7+
"include": ["biome.json", "commitlint.config.cjs", "src/**/*"]
158
},
169
"linter": {
1710
"enabled": true,
1811
"rules": {
1912
"recommended": true,
20-
"nursery": {
21-
"noEmptyTypeParameters": "error",
22-
"noInvalidUseBeforeDeclaration": "error",
23-
"noUnusedImports": "error",
24-
"noUnusedPrivateClassMembers": "error",
25-
"noUselessLoneBlockStatements": "error",
26-
"noUselessTernary": "error",
27-
"useExportType": "error",
28-
"useImportType": "error",
29-
"useForOf": "error",
30-
"useGroupedTypeImport": "error"
31-
},
3213
"complexity": {
3314
"noExcessiveCognitiveComplexity": "warn",
3415
"useSimplifiedLogicExpression": "error"
3516
},
3617
"correctness": {
37-
"noNewSymbol": "error"
18+
"noNewSymbol": "error",
19+
"noUnusedImports": "error",
20+
"noUnusedPrivateClassMembers": "error",
21+
"useHookAtTopLevel": "error"
3822
},
3923
"style": {
4024
"useBlockStatements": "error",
4125
"useCollapsedElseIf": "error",
26+
"useForOf": "error",
27+
"useFragmentSyntax": "error",
4228
"useShorthandArrayType": "error",
4329
"useShorthandAssign": "error",
4430
"useSingleCaseStatement": "error"
4531
},
4632
"suspicious": {
4733
"noApproximativeNumericConstant": "warn",
48-
"noConsoleLog": "error"
34+
"noConsoleLog": "error",
35+
"noEmptyBlockStatements": "error"
4936
}
5037
}
5138
},

examples/complete/src/entity/Article.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomUUID } from "crypto";
1+
import { randomUUID } from "node:crypto";
22
import { ZonedDateTime } from "@js-joda/core";
33
import { Entity, ManyToOne, PrimaryKey, Property, type Ref, Reference, t } from "@mikro-orm/core";
44
import { ZonedDateTimeType } from "mikro-orm-js-joda";

examples/complete/src/entity/Comment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomUUID } from "crypto";
1+
import { randomUUID } from "node:crypto";
22
import { ZonedDateTime } from "@js-joda/core";
33
import { Entity, ManyToOne, PrimaryKey, Property, type Ref, Reference, t } from "@mikro-orm/core";
44
import { ZonedDateTimeType } from "mikro-orm-js-joda";

examples/complete/src/entity/Person.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomUUID } from "crypto";
1+
import { randomUUID } from "node:crypto";
22
import { ZonedDateTime } from "@js-joda/core";
33
import { Entity, PrimaryKey, Property, t } from "@mikro-orm/core";
44
import { ZonedDateTimeType } from "mikro-orm-js-joda";

examples/complete/src/route/articles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
relationship,
88
resourceIdentifierSchema,
99
} from "koa-jsonapi-zod";
10-
import type { RouterContext, default as Router } from "koa-tree-router";
10+
import type { default as Router, RouterContext } from "koa-tree-router";
1111
import { z } from "zod";
1212
import { parseBaseQuery } from "../../../../src/index.js";
1313
import { Article } from "../entity/Article.js";

examples/complete/src/route/comments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseCreateRequest } from "koa-jsonapi-zod";
2-
import type { RouterContext, default as Router } from "koa-tree-router";
2+
import type { default as Router, RouterContext } from "koa-tree-router";
33
import { z } from "zod";
44
import { JsonApiErrorBody, relationship, resourceIdentifierSchema } from "../../../../src/index.js";
55
import { Article } from "../entity/Article.js";

examples/complete/src/route/person.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseCreateRequest } from "koa-jsonapi-zod";
2-
import type { RouterContext, default as Router } from "koa-tree-router";
2+
import type { default as Router, RouterContext } from "koa-tree-router";
33
import { z } from "zod";
44
import { Person } from "../entity/Person.js";
55
import { serializeManager } from "../json-api/index.js";

lefthook.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ pre-commit:
22
commands:
33
check:
44
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
5-
run: npx biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again
5+
run: pnpm exec biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again
66

77
commit-msg:
8-
scripts:
9-
"commitlint.sh":
10-
runner: bash
8+
commands:
9+
lint-commit-msg:
10+
run: pnpm exec commitlint --edit

package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,31 @@
3838
"check": "biome check . --apply"
3939
},
4040
"devDependencies": {
41-
"@biomejs/biome": "1.5.2",
42-
"@commitlint/cli": "^18.6.0",
43-
"@commitlint/config-conventional": "^18.6.0",
44-
"@tsconfig/node20": "^20.1.2",
41+
"@biomejs/biome": "1.7.1",
42+
"@commitlint/cli": "^19.3.0",
43+
"@commitlint/config-conventional": "^19.2.2",
44+
"@tsconfig/node20": "^20.1.4",
4545
"@types/content-type": "^1.1.8",
4646
"@types/http-errors": "^2.0.4",
4747
"@types/koa": "^2.15.0",
48-
"@types/node": "^20.11.17",
49-
"@types/qs": "^6.9.11",
50-
"@vitest/coverage-v8": "^1.2.2",
48+
"@types/node": "^20.12.7",
49+
"@types/qs": "^6.9.15",
50+
"@vitest/coverage-v8": "^1.5.2",
5151
"c8": "^9.1.0",
52-
"glob": "^10.3.10",
53-
"lefthook": "^1.6.1",
54-
"typescript": "^5.3.3",
55-
"vitest": "^1.2.2",
56-
"zod": "^3.22.4"
52+
"glob": "^10.3.12",
53+
"lefthook": "^1.6.10",
54+
"typescript": "^5.4.5",
55+
"vitest": "^1.5.2",
56+
"zod": "^3.23.4"
5757
},
5858
"peerDependencies": {
5959
"zod": "^3.22.4"
6060
},
6161
"dependencies": {
6262
"@hapi/accept": "^6.0.3",
6363
"content-type": "^1.0.5",
64+
"deepmerge": "^4.3.1",
6465
"http-errors": "^2.0.0",
65-
"qs": "^6.11.2"
66+
"qs": "^6.12.1"
6667
}
6768
}

0 commit comments

Comments
 (0)