ts-japi 1.12.1 → 1.12.3
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/.commitlintrc.ts +1 -1
- package/.github/workflows/ci.yml +32 -0
- package/.github/workflows/release-notes.yml +53 -0
- package/.github/workflows/{release-please.yaml → release-please.yml} +6 -7
- package/.github/workflows/release.yml +147 -0
- package/.node-version +1 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +14 -0
- package/LICENSE +2 -1
- package/Makefile +1 -3
- package/README.md +307 -209
- package/benchmarks/playground.benchmark.ts +12 -12
- package/benchmarks/serializer.benchmark.ts +10 -10
- package/biome.json +141 -0
- package/lefthook.yml +12 -0
- package/lib/classes/cache.d.ts +4 -4
- package/lib/classes/cache.d.ts.map +1 -1
- package/lib/classes/cache.js +7 -5
- package/lib/classes/cache.js.map +1 -1
- package/lib/classes/error-serializer.d.ts +3 -3
- package/lib/classes/error-serializer.d.ts.map +1 -1
- package/lib/classes/error-serializer.js +18 -15
- package/lib/classes/error-serializer.js.map +1 -1
- package/lib/classes/linker.d.ts +3 -3
- package/lib/classes/linker.d.ts.map +1 -1
- package/lib/classes/metaizer.d.ts +2 -2
- package/lib/classes/metaizer.d.ts.map +1 -1
- package/lib/classes/paginator.d.ts +5 -5
- package/lib/classes/paginator.d.ts.map +1 -1
- package/lib/classes/paginator.js +6 -5
- package/lib/classes/paginator.js.map +1 -1
- package/lib/classes/polymorphic-serialiser.d.ts +9 -10
- package/lib/classes/polymorphic-serialiser.d.ts.map +1 -1
- package/lib/classes/polymorphic-serialiser.js +15 -6
- package/lib/classes/polymorphic-serialiser.js.map +1 -1
- package/lib/classes/relator.d.ts +11 -11
- package/lib/classes/relator.d.ts.map +1 -1
- package/lib/classes/relator.js +15 -6
- package/lib/classes/relator.js.map +1 -1
- package/lib/classes/serializer.d.ts +9 -9
- package/lib/classes/serializer.d.ts.map +1 -1
- package/lib/classes/serializer.js +38 -27
- package/lib/classes/serializer.js.map +1 -1
- package/lib/index.d.ts +21 -21
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -9
- package/lib/index.js.map +1 -1
- package/lib/interfaces/cache.interface.d.ts +1 -1
- package/lib/interfaces/cache.interface.d.ts.map +1 -1
- package/lib/interfaces/error-serializer.interface.d.ts +37 -37
- package/lib/interfaces/error-serializer.interface.d.ts.map +1 -1
- package/lib/interfaces/error.interface.d.ts +21 -21
- package/lib/interfaces/error.interface.d.ts.map +1 -1
- package/lib/interfaces/json-api.interface.d.ts +12 -12
- package/lib/interfaces/json-api.interface.d.ts.map +1 -1
- package/lib/interfaces/linker.interface.d.ts +1 -1
- package/lib/interfaces/linker.interface.d.ts.map +1 -1
- package/lib/interfaces/paginator.interface.d.ts +2 -2
- package/lib/interfaces/paginator.interface.d.ts.map +1 -1
- package/lib/interfaces/relator.interface.d.ts +3 -3
- package/lib/interfaces/relator.interface.d.ts.map +1 -1
- package/lib/interfaces/serializer.interface.d.ts +78 -78
- package/lib/interfaces/serializer.interface.d.ts.map +1 -1
- package/lib/models/error.model.d.ts +4 -4
- package/lib/models/error.model.d.ts.map +1 -1
- package/lib/models/error.model.js +29 -18
- package/lib/models/error.model.js.map +1 -1
- package/lib/models/link.model.d.ts +1 -1
- package/lib/models/link.model.d.ts.map +1 -1
- package/lib/models/relationship.model.d.ts +5 -5
- package/lib/models/relationship.model.d.ts.map +1 -1
- package/lib/models/relationship.model.js +8 -5
- package/lib/models/relationship.model.js.map +1 -1
- package/lib/models/resource-identifier.model.d.ts +1 -1
- package/lib/models/resource-identifier.model.d.ts.map +1 -1
- package/lib/models/resource-identifier.model.js +2 -1
- package/lib/models/resource-identifier.model.js.map +1 -1
- package/lib/models/resource.model.d.ts +5 -5
- package/lib/models/resource.model.d.ts.map +1 -1
- package/lib/models/resource.model.js +6 -3
- package/lib/models/resource.model.js.map +1 -1
- package/lib/types/global.types.d.ts +9 -9
- package/lib/types/global.types.d.ts.map +1 -1
- package/lib/utils/is-error-document.d.ts +1 -1
- package/lib/utils/is-error-document.d.ts.map +1 -1
- package/lib/utils/is-error-document.js +3 -4
- package/lib/utils/is-error-document.js.map +1 -1
- package/lib/utils/is-object.d.ts.map +1 -1
- package/lib/utils/is-object.js +3 -3
- package/lib/utils/is-object.js.map +1 -1
- package/lib/utils/is-plain-object.d.ts.map +1 -1
- package/lib/utils/is-plain-object.js +9 -6
- package/lib/utils/is-plain-object.js.map +1 -1
- package/lib/utils/merge.d.ts +1 -1
- package/lib/utils/merge.d.ts.map +1 -1
- package/lib/utils/merge.js +5 -3
- package/lib/utils/merge.js.map +1 -1
- package/lib/utils/serializer.utils.d.ts +4 -4
- package/lib/utils/serializer.utils.d.ts.map +1 -1
- package/lib/utils/serializer.utils.js +35 -22
- package/lib/utils/serializer.utils.js.map +1 -1
- package/package.json +48 -66
- package/release-please-config.json +8 -3
- package/tsconfig.json +4 -3
- package/.github/release-please.yml +0 -4
- package/.github/workflows/ci.yaml +0 -73
- package/.github/workflows/publish.yaml +0 -29
- package/.husky/pre-commit +0 -4
- package/.husky/pre-push +0 -4
- package/.prettierignore +0 -4
- package/.prettierrc +0 -10
- package/api-extractor.json +0 -14
- package/tools/generate_docs.ts +0 -33
- package/tools/internal/custom_markdown_action.ts +0 -32
- package/tools/internal/custom_markdown_documenter.ts +0 -1337
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import Benchmark from
|
|
1
|
+
import Benchmark from "benchmark";
|
|
2
2
|
|
|
3
3
|
const suite = new Benchmark.Suite();
|
|
4
4
|
|
|
5
5
|
const a: any = new Map();
|
|
6
|
-
a.set(
|
|
6
|
+
a.set("test", "test");
|
|
7
7
|
|
|
8
8
|
const b: any = {};
|
|
9
|
-
b.test =
|
|
9
|
+
b.test = "test";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const length = 100; // user defined length
|
|
12
12
|
|
|
13
13
|
const array: number[] = [];
|
|
14
14
|
const map = new Map();
|
|
15
15
|
|
|
16
|
-
for (
|
|
16
|
+
for (let i = 0; i < length; i++) {
|
|
17
17
|
array.push(i);
|
|
18
18
|
map.set(i, 0);
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const _tobepushed = [1, 2, 3];
|
|
21
21
|
|
|
22
22
|
// add tests
|
|
23
23
|
suite
|
|
24
|
-
.add(
|
|
24
|
+
.add("Array#ForOf", async () => {
|
|
25
25
|
const g = [];
|
|
26
26
|
for (const test of array) {
|
|
27
27
|
g.push(test);
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
|
-
.add(
|
|
30
|
+
.add("Array#index", async () => {
|
|
31
31
|
const g = [];
|
|
32
32
|
for (let i = 0, len = array.length; i < len; i++) {
|
|
33
33
|
g.push(array[i]);
|
|
34
34
|
}
|
|
35
35
|
})
|
|
36
|
-
.add(
|
|
36
|
+
.add("Array#indexWithTemp", async () => {
|
|
37
37
|
const g = [];
|
|
38
38
|
for (let i = 0, temp = array[i]; i < array.length; temp = array[++i]) {
|
|
39
39
|
g.push(temp);
|
|
40
40
|
}
|
|
41
41
|
})
|
|
42
42
|
// add listeners
|
|
43
|
-
.on(
|
|
43
|
+
.on("cycle", (event: any) => {
|
|
44
44
|
console.log(String(event.target));
|
|
45
45
|
})
|
|
46
|
-
.on(
|
|
47
|
-
console.log(
|
|
46
|
+
.on("complete", function (this: any) {
|
|
47
|
+
console.log(`Fastest is ${this.filter("fastest").map("name")}`);
|
|
48
48
|
})
|
|
49
49
|
// run async
|
|
50
50
|
.run({ async: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Benchmark from
|
|
2
|
-
import { Relator, Serializer } from
|
|
3
|
-
import { Article, Comment, User } from
|
|
1
|
+
import Benchmark from "benchmark";
|
|
2
|
+
import { Relator, Serializer } from "../src";
|
|
3
|
+
import { Article, Comment, User } from "../test/models";
|
|
4
4
|
|
|
5
5
|
const suite = new Benchmark.Suite();
|
|
6
6
|
|
|
@@ -13,12 +13,12 @@ for (let i = 0; i < 5; i++) {
|
|
|
13
13
|
for (let i = 0; i < 10; i++) {
|
|
14
14
|
Comment.save(new Comment(String(i), User.storage[0], Article.storage[0]));
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const UserSerializer = new Serializer<User>("users", {
|
|
17
17
|
depth: 0, // Change to 2 to see the difference
|
|
18
18
|
cache: true,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const CommentSerializer = new Serializer<Comment>("comments");
|
|
21
|
+
const ArticleSerializer = new Serializer<Article>("articles");
|
|
22
22
|
const UserArticleRelator = new Relator<User, Article>(
|
|
23
23
|
async (user: User) => user.getArticles(),
|
|
24
24
|
ArticleSerializer
|
|
@@ -39,15 +39,15 @@ const user = User.storage[0];
|
|
|
39
39
|
|
|
40
40
|
// add tests
|
|
41
41
|
suite
|
|
42
|
-
.add(
|
|
42
|
+
.add("Serializer#Test", async () => {
|
|
43
43
|
await UserSerializer.serialize(user);
|
|
44
44
|
})
|
|
45
45
|
// add listeners
|
|
46
|
-
.on(
|
|
46
|
+
.on("cycle", (event: any) => {
|
|
47
47
|
console.log(String(event.target));
|
|
48
48
|
})
|
|
49
|
-
.on(
|
|
50
|
-
console.log(
|
|
49
|
+
.on("complete", function (this: any) {
|
|
50
|
+
console.log(`Fastest is ${this.filter("fastest").map("name")}`);
|
|
51
51
|
})
|
|
52
52
|
// run async
|
|
53
53
|
.run({ async: true });
|
package/biome.json
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": true,
|
|
10
|
+
"includes": [
|
|
11
|
+
"!node_modules",
|
|
12
|
+
"!dist",
|
|
13
|
+
"!build",
|
|
14
|
+
"!**/dist",
|
|
15
|
+
"!**/build",
|
|
16
|
+
"!.pnpm-store"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"formatter": {
|
|
20
|
+
"enabled": true,
|
|
21
|
+
"indentStyle": "space",
|
|
22
|
+
"indentWidth": 2
|
|
23
|
+
},
|
|
24
|
+
"linter": {
|
|
25
|
+
"enabled": true,
|
|
26
|
+
"rules": {
|
|
27
|
+
"recommended": true,
|
|
28
|
+
"style": {
|
|
29
|
+
"useConsistentMemberAccessibility": "off",
|
|
30
|
+
"noParameterProperties": "off"
|
|
31
|
+
},
|
|
32
|
+
"suspicious": {
|
|
33
|
+
"noExplicitAny": "off"
|
|
34
|
+
},
|
|
35
|
+
"complexity": {
|
|
36
|
+
"noExcessiveCognitiveComplexity": "off"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"assist": {
|
|
41
|
+
"actions": {
|
|
42
|
+
"source": {
|
|
43
|
+
"organizeImports": "on"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"extends": ["ultracite/core"],
|
|
48
|
+
"overrides": [
|
|
49
|
+
{
|
|
50
|
+
"includes": ["src/index.ts"],
|
|
51
|
+
"linter": {
|
|
52
|
+
"rules": {
|
|
53
|
+
"performance": { "noBarrelFile": "off" }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"includes": ["test/models/index.ts"],
|
|
59
|
+
"linter": {
|
|
60
|
+
"rules": {
|
|
61
|
+
"style": { "noExportedImports": "off" }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"includes": ["test/issue-62/**"],
|
|
67
|
+
"linter": {
|
|
68
|
+
"rules": {
|
|
69
|
+
"style": { "noNamespace": "off" }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"includes": ["test/models/**"],
|
|
75
|
+
"linter": {
|
|
76
|
+
"rules": {
|
|
77
|
+
"suspicious": { "noUnsafeDeclarationMerging": "off" }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"includes": ["tools/**"],
|
|
83
|
+
"linter": {
|
|
84
|
+
"rules": {
|
|
85
|
+
"style": {
|
|
86
|
+
"useFilenamingConvention": "off",
|
|
87
|
+
"useDefaultSwitchClause": "off",
|
|
88
|
+
"noNonNullAssertion": "off"
|
|
89
|
+
},
|
|
90
|
+
"performance": { "noNamespaceImport": "off" }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"includes": ["benchmarks/**"],
|
|
96
|
+
"linter": {
|
|
97
|
+
"rules": {
|
|
98
|
+
"suspicious": {
|
|
99
|
+
"useAwait": "off",
|
|
100
|
+
"noEvolvingTypes": "off",
|
|
101
|
+
"noImplicitAnyLet": "off"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"includes": [
|
|
108
|
+
"src/classes/polymorphic-serialiser.ts",
|
|
109
|
+
"test/issue-23.test.ts"
|
|
110
|
+
],
|
|
111
|
+
"linter": {
|
|
112
|
+
"rules": {
|
|
113
|
+
"suspicious": { "useAwait": "off" }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"includes": ["test/**"],
|
|
119
|
+
"linter": {
|
|
120
|
+
"rules": {
|
|
121
|
+
"suspicious": {
|
|
122
|
+
"noEvolvingTypes": "off",
|
|
123
|
+
"noImplicitAnyLet": "off",
|
|
124
|
+
"useAwait": "off"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"includes": ["src/classes/serializer.ts"],
|
|
131
|
+
"linter": {
|
|
132
|
+
"rules": {
|
|
133
|
+
"suspicious": {
|
|
134
|
+
"noEvolvingTypes": "off",
|
|
135
|
+
"noImplicitAnyLet": "off"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
package/lefthook.yml
ADDED
package/lib/classes/cache.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CacheOptions } from
|
|
2
|
-
import { DataDocument } from
|
|
3
|
-
import { SerializerOptions } from
|
|
4
|
-
import { Dictionary, nullish, SingleOrArray } from
|
|
1
|
+
import type { CacheOptions } from "../interfaces/cache.interface";
|
|
2
|
+
import type { DataDocument } from "../interfaces/json-api.interface";
|
|
3
|
+
import type { SerializerOptions } from "../interfaces/serializer.interface";
|
|
4
|
+
import type { Dictionary, nullish, SingleOrArray } from "../types/global.types";
|
|
5
5
|
export default class Cache<PrimaryType extends Dictionary<any>> {
|
|
6
6
|
/**
|
|
7
7
|
* The default max for document storage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/classes/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/classes/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEhF,MAAM,CAAC,OAAO,OAAO,KAAK,CAAC,WAAW,SAAS,UAAU,CAAC,GAAG,CAAC;IAC5D;;OAEG;IACH,OAAc,YAAY,SAAM;IAEhC,0CAA0C;IAC1C,OAAO,CAAC,OAAO,CAIN;IAET;;OAEG;IACH,OAAO,CAAC,KAAK,CAA8B;IAE3C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAGS;IAEzB;;;;OAIG;gBACgB,OAAO,GAAE,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAM;IASnE,6CAA6C;IACtC,GAAG,CACR,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,OAAO,EAC1C,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAYnD,6CAA6C;IACtC,GAAG,CACR,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,OAAO,EAC1C,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAC5C,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAQpD"}
|
package/lib/classes/cache.js
CHANGED
|
@@ -21,18 +21,20 @@ class Cache {
|
|
|
21
21
|
* @param limit - The maximum amount of documents that can be stored before erasure.
|
|
22
22
|
*/
|
|
23
23
|
constructor(options = {}) {
|
|
24
|
-
if (options.limit)
|
|
24
|
+
if (options.limit) {
|
|
25
25
|
this.limit = options.limit;
|
|
26
|
-
|
|
26
|
+
}
|
|
27
|
+
if (options.resolver) {
|
|
27
28
|
this.resolver = options.resolver;
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
/** @internal Gets a document in the cache */
|
|
30
32
|
get(data, options) {
|
|
31
33
|
const document = this.storage.find(([storedData, storedOptions]) => this.resolver(storedData, data) && Object.is(storedOptions, options));
|
|
32
|
-
if (document)
|
|
34
|
+
if (document) {
|
|
33
35
|
return document[2];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
36
38
|
}
|
|
37
39
|
/** @internal Sets a document in the cache */
|
|
38
40
|
set(data, document, options) {
|
package/lib/classes/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/classes/cache.ts"],"names":[],"mappings":";;AAKA,MAAqB,KAAK;IACxB;;OAEG;IACI,MAAM,CAAC,YAAY,GAAG,EAAE,CAAC;IAEhC,0CAA0C;IAClC,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/classes/cache.ts"],"names":[],"mappings":";;AAKA,MAAqB,KAAK;IACxB;;OAEG;IACI,MAAM,CAAC,YAAY,GAAG,EAAE,CAAC;IAEhC,0CAA0C;IAClC,OAAO,GAIT,EAAE,CAAC;IAET;;OAEG;IACK,KAAK,GAAW,KAAK,CAAC,YAAY,CAAC;IAE3C;;OAEG;IACK,QAAQ,GAGD,MAAM,CAAC,EAAE,CAAC;IAEzB;;;;OAIG;IACH,YAAmB,UAA8C,EAAE;QACjE,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC7B,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACnC,CAAC;IACH,CAAC;IAED,6CAA6C;IACtC,GAAG,CACR,IAA0C,EAC1C,OAAiD;QAEjD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAChC,CAAC,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE,EAAE,CAC9B,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CACvE,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6CAA6C;IACtC,GAAG,CACR,IAA0C,EAC1C,QAA4C,EAC5C,OAAiD;QAEjD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC;IAClB,CAAC;;AAlEH,wBAmEC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ErrorSerializerOptions } from
|
|
2
|
-
import { ErrorDocument } from
|
|
3
|
-
import { Dictionary, SingleOrArray } from
|
|
1
|
+
import type { ErrorSerializerOptions } from "../interfaces/error-serializer.interface";
|
|
2
|
+
import type { ErrorDocument } from "../interfaces/json-api.interface";
|
|
3
|
+
import type { Dictionary, SingleOrArray } from "../types/global.types";
|
|
4
4
|
/**
|
|
5
5
|
* The {@link ErrorSerializer} class is used to serialize errors.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-serializer.d.ts","sourceRoot":"","sources":["../../src/classes/error-serializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error-serializer.d.ts","sourceRoot":"","sources":["../../src/classes/error-serializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGvE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe,CAAC,SAAS,SAAS,UAAU,CAAC,GAAG,CAAC;IACpE;;OAEG;IACH,OAAc,cAAc;;;;;;;;;;;;;;;;MAgB1B;IAEF;;OAEG;IACH,OAAO,CAAC,OAAO,CAA8C;IAE7D;;;;;OAKG;gBACgB,OAAO,GAAE,OAAO,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAM;IAK3E;;;;;OAKG;IACI,SAAS,CACd,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,EAChC,OAAO,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;CAyFvD"}
|
|
@@ -18,15 +18,15 @@ class ErrorSerializer {
|
|
|
18
18
|
* Default options. Can be edited to change default options globally.
|
|
19
19
|
*/
|
|
20
20
|
static defaultOptions = {
|
|
21
|
-
version:
|
|
21
|
+
version: "1.0",
|
|
22
22
|
attributes: {
|
|
23
|
-
id:
|
|
24
|
-
status:
|
|
25
|
-
code:
|
|
26
|
-
title:
|
|
27
|
-
detail:
|
|
23
|
+
id: "id",
|
|
24
|
+
status: "code",
|
|
25
|
+
code: "name",
|
|
26
|
+
title: "reason",
|
|
27
|
+
detail: "message",
|
|
28
28
|
source: {
|
|
29
|
-
pointer:
|
|
29
|
+
pointer: "location",
|
|
30
30
|
parameter: undefined,
|
|
31
31
|
header: undefined,
|
|
32
32
|
},
|
|
@@ -57,20 +57,20 @@ class ErrorSerializer {
|
|
|
57
57
|
serialize(errors, options) {
|
|
58
58
|
// Get options.
|
|
59
59
|
let o = this.options;
|
|
60
|
-
if (options)
|
|
60
|
+
if (options) {
|
|
61
61
|
o = (0, merge_1.default)({}, this.options, options);
|
|
62
|
+
}
|
|
62
63
|
const attributes = o.attributes;
|
|
63
64
|
const linkers = o.linkers;
|
|
64
65
|
const metaizers = o.metaizers;
|
|
65
66
|
const version = o.version;
|
|
66
67
|
const document = { errors: [] };
|
|
67
68
|
// Normalize error input
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
document.errors = errors.map((e) => {
|
|
72
|
-
if (e instanceof error_model_1.default)
|
|
69
|
+
const normalizedErrors = Array.isArray(errors) ? errors : [errors];
|
|
70
|
+
document.errors = normalizedErrors.map((e) => {
|
|
71
|
+
if (e instanceof error_model_1.default) {
|
|
73
72
|
return e;
|
|
73
|
+
}
|
|
74
74
|
const eo = {};
|
|
75
75
|
if (attributes.id && e[attributes.id]) {
|
|
76
76
|
eo.id = String(e[attributes.id]);
|
|
@@ -99,7 +99,7 @@ class ErrorSerializer {
|
|
|
99
99
|
eo.source.header = String(e[attributes.source.header]);
|
|
100
100
|
}
|
|
101
101
|
if (Object.keys(eo.source).length === 0) {
|
|
102
|
-
|
|
102
|
+
eo.source = undefined;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
return new error_model_1.default(eo);
|
|
@@ -110,7 +110,10 @@ class ErrorSerializer {
|
|
|
110
110
|
}
|
|
111
111
|
// Handling document metadata.
|
|
112
112
|
if (metaizers.jsonapi) {
|
|
113
|
-
document.jsonapi = {
|
|
113
|
+
document.jsonapi = {
|
|
114
|
+
...document.jsonapi,
|
|
115
|
+
meta: metaizers.jsonapi.metaize(),
|
|
116
|
+
};
|
|
114
117
|
}
|
|
115
118
|
if (metaizers.document) {
|
|
116
119
|
document.meta = metaizers.document.metaize(document.errors);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-serializer.js","sourceRoot":"","sources":["../../src/classes/error-serializer.ts"],"names":[],"mappings":";;;;;AAGA,wEAA8C;AAE9C,2DAAmC;AAEnC;;;;;;;GAOG;AACH,MAAqB,eAAe;IAClC;;OAEG;IACI,MAAM,CAAC,cAAc,GAAG;QAC7B,OAAO,EAAE,KAAK;QACd,UAAU,EAAE;YACV,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE;gBACN,OAAO,EAAE,UAAU;gBACnB,SAAS,EAAE,SAAS;gBACpB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF;;OAEG;IACK,OAAO,CAA8C;IAE7D;;;;;OAKG;IACH,YAAmB,UAAsD,EAAE;QACzE,2BAA2B;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAA,eAAK,EAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED;;;;;OAKG;IACI,SAAS,CACd,MAAgC,EAChC,OAAoD;QAEpD,eAAe;QACf,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACrB,IAAI,OAAO;
|
|
1
|
+
{"version":3,"file":"error-serializer.js","sourceRoot":"","sources":["../../src/classes/error-serializer.ts"],"names":[],"mappings":";;;;;AAGA,wEAA8C;AAE9C,2DAAmC;AAEnC;;;;;;;GAOG;AACH,MAAqB,eAAe;IAClC;;OAEG;IACI,MAAM,CAAC,cAAc,GAAG;QAC7B,OAAO,EAAE,KAAK;QACd,UAAU,EAAE;YACV,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE;gBACN,OAAO,EAAE,UAAU;gBACnB,SAAS,EAAE,SAAS;gBACpB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF;;OAEG;IACK,OAAO,CAA8C;IAE7D;;;;;OAKG;IACH,YAAmB,UAAsD,EAAE;QACzE,2BAA2B;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAA,eAAK,EAAC,EAAE,EAAE,eAAe,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED;;;;;OAKG;IACI,SAAS,CACd,MAAgC,EAChC,OAAoD;QAEpD,eAAe;QACf,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,CAAC,GAAG,IAAA,eAAK,EAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,MAAM,UAAU,GAA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C;YACH,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;;AAtIH,kCAuIC"}
|
package/lib/classes/linker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LinkerOptions } from
|
|
2
|
-
import Link from
|
|
3
|
-
import { VariadicFunction } from
|
|
1
|
+
import type { LinkerOptions } from "../interfaces/linker.interface";
|
|
2
|
+
import Link from "../models/link.model";
|
|
3
|
+
import type { VariadicFunction } from "../types/global.types";
|
|
4
4
|
/**
|
|
5
5
|
* The {@link Linker} class is used to construct a [link](https://jsonapi.org/format/#document-links).
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/classes/linker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/classes/linker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM,CAAC,YAAY,SAAS,GAAG,EAAE;IACpD,0CAA0C;IACnC,IAAI,EAAE,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAElD;;;;;OAKG;gBAED,IAAI,EAAE,gBAAgB,CAAC,YAAY,EAAE,MAAM,CAAC,EAC5C,OAAO,GAAE,aAAa,CAAC,YAAY,CAAM;CAQ5C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Meta from
|
|
2
|
-
import { Dictionary, VariadicFunction } from
|
|
1
|
+
import Meta from "../models/meta.model";
|
|
2
|
+
import type { Dictionary, VariadicFunction } from "../types/global.types";
|
|
3
3
|
/**
|
|
4
4
|
* The {@link Metaizer} class is used to construct [meta information](https://jsonapi.org/format/#document-meta).
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaizer.d.ts","sourceRoot":"","sources":["../../src/classes/metaizer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"metaizer.d.ts","sourceRoot":"","sources":["../../src/classes/metaizer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ,CAAC,YAAY,SAAS,GAAG,EAAE;IACtD,0CAA0C;IACnC,OAAO,EAAE,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAErD;;;;;OAKG;gBACgB,OAAO,EAAE,gBAAgB,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CAG5E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PaginationOf } from
|
|
2
|
-
import Link from
|
|
3
|
-
import { SingleOrArray } from
|
|
1
|
+
import type { PaginationOf } from "../interfaces/paginator.interface";
|
|
2
|
+
import Link from "../models/link.model";
|
|
3
|
+
import type { SingleOrArray } from "../types/global.types";
|
|
4
4
|
/**
|
|
5
5
|
* The {@link Paginator} class is used to construct [pagination links](https://jsonapi.org/format/#fetching-pagination).
|
|
6
6
|
*
|
|
@@ -11,12 +11,12 @@ import { SingleOrArray } from '../types/global.types';
|
|
|
11
11
|
*/
|
|
12
12
|
export default class Paginator<DataType> {
|
|
13
13
|
/** @internal Generates pagination links. */
|
|
14
|
-
paginate: (data: SingleOrArray<DataType>) => PaginationOf<Link> |
|
|
14
|
+
paginate: (data: SingleOrArray<DataType>) => PaginationOf<Link> | undefined;
|
|
15
15
|
/**
|
|
16
16
|
* Creates a {@link Paginator}.
|
|
17
17
|
*
|
|
18
18
|
* @param paginate - A function to generate pagination links from data.
|
|
19
19
|
*/
|
|
20
|
-
constructor(paginate: (data: SingleOrArray<DataType>) => PaginationOf<string> |
|
|
20
|
+
constructor(paginate: (data: SingleOrArray<DataType>) => PaginationOf<string> | undefined);
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=paginator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/classes/paginator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../src/classes/paginator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,IAAI,MAAM,sBAAsB,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS,CAAC,QAAQ;IACrC,4CAA4C;IACrC,QAAQ,EAAE,CACf,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,KAC1B,YAAY,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;gBAED,QAAQ,EAAE,CACR,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,KAC1B,YAAY,CAAC,MAAM,CAAC,GAAG,SAAS;CAqBxC"}
|
package/lib/classes/paginator.js
CHANGED
|
@@ -23,13 +23,14 @@ class Paginator {
|
|
|
23
23
|
constructor(paginate) {
|
|
24
24
|
this.paginate = (data) => {
|
|
25
25
|
const links = paginate(data);
|
|
26
|
-
if (!links)
|
|
26
|
+
if (!links) {
|
|
27
27
|
return;
|
|
28
|
+
}
|
|
28
29
|
return {
|
|
29
|
-
first: typeof links.first ===
|
|
30
|
-
last: typeof links.last ===
|
|
31
|
-
prev: typeof links.prev ===
|
|
32
|
-
next: typeof links.next ===
|
|
30
|
+
first: typeof links.first === "string" ? new link_model_1.default(links.first) : links.first,
|
|
31
|
+
last: typeof links.last === "string" ? new link_model_1.default(links.last) : links.last,
|
|
32
|
+
prev: typeof links.prev === "string" ? new link_model_1.default(links.prev) : links.prev,
|
|
33
|
+
next: typeof links.next === "string" ? new link_model_1.default(links.next) : links.next,
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginator.js","sourceRoot":"","sources":["../../src/classes/paginator.ts"],"names":[],"mappings":";;;;;AACA,sEAAwC;AAGxC;;;;;;;GAOG;AACH,MAAqB,SAAS;IAC5B,4CAA4C;IACrC,QAAQ,
|
|
1
|
+
{"version":3,"file":"paginator.js","sourceRoot":"","sources":["../../src/classes/paginator.ts"],"names":[],"mappings":";;;;;AACA,sEAAwC;AAGxC;;;;;;;GAOG;AACH,MAAqB,SAAS;IAC5B,4CAA4C;IACrC,QAAQ,CAEqB;IAEpC;;;;OAIG;IACH,YACE,QAEqC;QAErC,IAAI,CAAC,QAAQ,GAAG,CACd,IAA6B,EACG,EAAE;YAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YACD,OAAO;gBACL,KAAK,EACH,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,oBAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK;gBACvE,IAAI,EACF,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,oBAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI;gBACpE,IAAI,EACF,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,oBAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI;gBACpE,IAAI,EACF,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,oBAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI;aACrE,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF;AAnCD,4BAmCC"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { DataDocument } from
|
|
2
|
-
import { SerializerOptions } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { Dictionary, nullish, SingleOrArray } from
|
|
6
|
-
import { Helpers } from
|
|
7
|
-
import Relator from
|
|
8
|
-
import Serializer from
|
|
1
|
+
import type { DataDocument } from "../interfaces/json-api.interface";
|
|
2
|
+
import type { SerializerOptions } from "../interfaces/serializer.interface";
|
|
3
|
+
import type Resource from "../models/resource.model";
|
|
4
|
+
import type ResourceIdentifier from "../models/resource-identifier.model";
|
|
5
|
+
import type { Dictionary, nullish, SingleOrArray } from "../types/global.types";
|
|
6
|
+
import type { Helpers } from "../utils/serializer.utils";
|
|
7
|
+
import type Relator from "./relator";
|
|
8
|
+
import Serializer from "./serializer";
|
|
9
9
|
export default class PolymorphicSerializer<PrimaryType extends Dictionary<any>> extends Serializer<PrimaryType> {
|
|
10
10
|
private serialisers;
|
|
11
11
|
private key;
|
|
12
|
-
constructor(commonName: string, key: keyof PrimaryType, serializers: Record<string, Serializer>);
|
|
13
|
-
constructor(commonName: string, key: keyof PrimaryType, serializers: Record<string, () => Serializer>);
|
|
12
|
+
constructor(commonName: string, key: keyof PrimaryType, serializers: Record<string, () => Serializer> | Record<string, Serializer>);
|
|
14
13
|
serialize(data: SingleOrArray<PrimaryType> | nullish, options?: Partial<SerializerOptions<PrimaryType>>): Promise<Partial<DataDocument<PrimaryType>>>;
|
|
15
14
|
createIdentifier(data: PrimaryType, options?: SerializerOptions<PrimaryType>): ResourceIdentifier;
|
|
16
15
|
createResource(data: PrimaryType, options?: Partial<SerializerOptions<PrimaryType>>, helpers?: Helpers<PrimaryType>, relatorDataCache?: Map<Relator<any>, Dictionary<any>[]>): Promise<Resource<PrimaryType>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polymorphic-serialiser.d.ts","sourceRoot":"","sources":["../../src/classes/polymorphic-serialiser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"polymorphic-serialiser.d.ts","sourceRoot":"","sources":["../../src/classes/polymorphic-serialiser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,kBAAkB,MAAM,qCAAqC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,MAAM,CAAC,OAAO,OAAO,qBAAqB,CACxC,WAAW,SAAS,UAAU,CAAC,GAAG,CAAC,CACnC,SAAQ,UAAU,CAAC,WAAW,CAAC;IAC/B,OAAO,CAAC,WAAW,CAEkB;IAErC,OAAO,CAAC,GAAG,CAAoB;gBAE7B,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,WAAW,EACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAY/D,SAAS,CACpB,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,OAAO,EAC1C,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,GAChD,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC;IA+FvC,gBAAgB,CACrB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,GACvC,kBAAkB;IAQR,cAAc,CACzB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,EACjD,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,EAC9B,gBAAgB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,GACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAanB,aAAa;IAa3B,OAAO,CAAC,oBAAoB;CAW7B"}
|
|
@@ -34,11 +34,17 @@ class PolymorphicSerializer extends serializer_1.default {
|
|
|
34
34
|
document.jsonapi = { ...document.jsonapi, version: options.version };
|
|
35
35
|
}
|
|
36
36
|
if (options?.metaizers?.jsonapi) {
|
|
37
|
-
document.jsonapi = {
|
|
37
|
+
document.jsonapi = {
|
|
38
|
+
...document.jsonapi,
|
|
39
|
+
meta: options.metaizers.jsonapi.metaize(),
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
42
|
document = documents.reduce((result, document) => {
|
|
40
43
|
result.data = [result.data ?? [], document.data ?? []].flat();
|
|
41
|
-
result.included = [
|
|
44
|
+
result.included = [
|
|
45
|
+
result.included ?? [],
|
|
46
|
+
document.included ?? [],
|
|
47
|
+
].flat();
|
|
42
48
|
return result;
|
|
43
49
|
}, document);
|
|
44
50
|
// Sort data to match input order - this is important for cases where
|
|
@@ -57,7 +63,10 @@ class PolymorphicSerializer extends serializer_1.default {
|
|
|
57
63
|
// Handle links
|
|
58
64
|
if (options?.linkers) {
|
|
59
65
|
if (options.linkers.document) {
|
|
60
|
-
document.links = {
|
|
66
|
+
document.links = {
|
|
67
|
+
...document.links,
|
|
68
|
+
self: options.linkers.document.link(data),
|
|
69
|
+
};
|
|
61
70
|
}
|
|
62
71
|
if (options.linkers.paginator) {
|
|
63
72
|
const pagination = options.linkers.paginator.paginate(data);
|
|
@@ -68,11 +77,11 @@ class PolymorphicSerializer extends serializer_1.default {
|
|
|
68
77
|
}
|
|
69
78
|
return document;
|
|
70
79
|
}
|
|
71
|
-
|
|
80
|
+
if (data) {
|
|
72
81
|
return this.serializeType(data, options);
|
|
73
82
|
}
|
|
74
83
|
const serialiser = Object.values(this.serialisers)[0];
|
|
75
|
-
if (typeof serialiser ===
|
|
84
|
+
if (typeof serialiser === "function") {
|
|
76
85
|
return serialiser().serialize(data, options);
|
|
77
86
|
}
|
|
78
87
|
return serialiser.serialize(data, options);
|
|
@@ -101,7 +110,7 @@ class PolymorphicSerializer extends serializer_1.default {
|
|
|
101
110
|
getSerializerForData(data) {
|
|
102
111
|
const serialiser = this.serialisers[data[this.key]];
|
|
103
112
|
if (serialiser) {
|
|
104
|
-
if (typeof serialiser ===
|
|
113
|
+
if (typeof serialiser === "function") {
|
|
105
114
|
return serialiser();
|
|
106
115
|
}
|
|
107
116
|
return serialiser;
|