Skip to content

Commit 3710b27

Browse files
Андрис Цилдерманисolosegres
authored andcommitted
fix: missing jsona types
1 parent 0390772 commit 3710b27

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/JsonaTypes.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ export interface IJsonaDeserializer extends IJsonaModelBuilder {
4545
}
4646

4747
export interface IJsonDeserializerConstructor {
48-
new(propertiesMapper: IJsonPropertiesMapper, deserializeCache: IDeserializeCache, options);
48+
new(propertiesMapper: IJsonPropertiesMapper, deserializeCache: IDeserializeCache, options?: TDeserializeOptions): IJsonaDeserializer;
4949
}
5050

5151
export interface IModelsSerializer {
52-
setPropertiesMapper(propertiesMapper: IModelPropertiesMapper);
53-
setStuff(stuff);
54-
setIncludeNames(includeNames: TJsonaDenormalizedIncludeNames | TJsonaNormalizedIncludeNamesTree);
52+
setPropertiesMapper(propertiesMapper: IModelPropertiesMapper): void;
53+
setStuff(stuff: TJsonaModel | TJsonaModel[]): void;
54+
setIncludeNames(includeNames: TJsonaDenormalizedIncludeNames | TJsonaNormalizedIncludeNamesTree): void;
5555
build(): TJsonApiBody;
5656
buildDataByModel(model: TJsonaModel | null): TJsonApiData;
57-
buildRelationshipsByModel(model: TJsonaModel);
57+
buildRelationshipsByModel(model: TJsonaModel): TJsonaRelationshipDataItem[] | TJsonaModel | TJsonaRelationshipBuild;
5858
buildIncludedByModel(
59-
model: TJsonaModel,
60-
includeTree: TJsonaNormalizedIncludeNamesTree,
61-
builtIncluded: TJsonaUniqueIncluded
59+
model: TJsonaModel,
60+
includeTree: TJsonaNormalizedIncludeNamesTree,
61+
builtIncluded: TJsonaUniqueIncluded
6262
): void;
6363
buildIncludedItem(
64-
relationModel: TJsonaModel,
65-
subIncludeTree: TJsonaNormalizedIncludeNamesTree,
66-
builtIncluded: TJsonaUniqueIncluded
67-
);
64+
relationModel: TJsonaModel,
65+
subIncludeTree: TJsonaNormalizedIncludeNamesTree,
66+
builtIncluded: TJsonaUniqueIncluded
67+
): void;
6868
}
6969

7070
export interface IModelsSerializerConstructor {
@@ -113,7 +113,7 @@ type LinkKey = "self" | "related" | "first" | "prev" | "next" | "last";
113113
type LinkObjectMember = string | { href?: string; meta?: TAnyKeyValueObject } | null;
114114

115115
export type TJsonApiLinks = {
116-
[key in LinkKey]?: LinkObjectMember;
116+
[key in LinkKey]?: LinkObjectMember;
117117
};
118118

119119
export type TJsonApiRelationships = {
@@ -155,6 +155,11 @@ export type TJsonaModel = {
155155
[propertyName: string]: any
156156
};
157157

158+
export type TJsonaRelationshipDataItem = {
159+
id?: number | string,
160+
type: string;
161+
}
162+
158163
export type TResourceIdObj = {
159164
id?: string | number,
160165
type: string,

src/builders/ModelsSerializer.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
TJsonaNormalizedIncludeNamesTree,
77
TJsonaUniqueIncluded,
88
IModelPropertiesMapper,
9-
IModelsSerializer
9+
IModelsSerializer,
10+
TJsonaRelationshipDataItem,
1011
} from '../JsonaTypes';
1112

1213
import {createIncludeNamesTree} from '../utils';
@@ -27,7 +28,7 @@ export class ModelsSerializer implements IModelsSerializer {
2728
this.propertiesMapper = propertiesMapper;
2829
}
2930

30-
setStuff(stuff) {
31+
setStuff(stuff: TJsonaModel | TJsonaModel[]) {
3132
this.stuff = stuff;
3233
}
3334

@@ -61,13 +62,13 @@ export class ModelsSerializer implements IModelsSerializer {
6162

6263
for (let i = 0; i < collectionLength; i++) {
6364
data.push(
64-
this.buildDataByModel(stuff[i])
65+
this.buildDataByModel(stuff[i])
6566
);
6667

6768
this.buildIncludedByModel(
68-
stuff[i],
69-
this.includeNamesTree,
70-
uniqueIncluded
69+
stuff[i],
70+
this.includeNamesTree,
71+
uniqueIncluded
7172
);
7273
}
7374

@@ -77,9 +78,9 @@ export class ModelsSerializer implements IModelsSerializer {
7778
body['data'] = this.buildDataByModel(stuff);
7879

7980
this.buildIncludedByModel(
80-
stuff,
81-
this.includeNamesTree,
82-
uniqueIncluded
81+
stuff,
82+
this.includeNamesTree,
83+
uniqueIncluded
8384
);
8485
} else if (stuff === null) {
8586
body['data'] = null;
@@ -115,7 +116,7 @@ export class ModelsSerializer implements IModelsSerializer {
115116
return data;
116117
}
117118

118-
buildResourceObjectPart(relation: TJsonaModel) {
119+
buildResourceObjectPart(relation: TJsonaModel): TJsonaRelationshipDataItem {
119120
const id = this.propertiesMapper.getId(relation);
120121
const type = this.propertiesMapper.getType(relation);
121122

@@ -147,9 +148,9 @@ export class ModelsSerializer implements IModelsSerializer {
147148
relationshipData.push(relationshipDataItem);
148149
} else {
149150
console.error(
150-
`Can't create data item for relationship ${k},
151+
`Can't create data item for relationship ${k},
151152
it doesn't have 'id' or 'type', it was skipped`,
152-
relationItem
153+
relationItem
153154
);
154155
}
155156
}
@@ -166,8 +167,8 @@ export class ModelsSerializer implements IModelsSerializer {
166167
};
167168
} else {
168169
console.error(
169-
`Can't create data for relationship ${k}, it doesn't have 'type', it was skipped`,
170-
relation
170+
`Can't create data for relationship ${k}, it doesn't have 'type', it was skipped`,
171+
relation
171172
);
172173
}
173174
} else {
@@ -181,9 +182,9 @@ export class ModelsSerializer implements IModelsSerializer {
181182
}
182183

183184
buildIncludedByModel(
184-
model: TJsonaModel,
185-
includeTree: TJsonaNormalizedIncludeNamesTree,
186-
builtIncluded: TJsonaUniqueIncluded = {}
185+
model: TJsonaModel,
186+
includeTree: TJsonaNormalizedIncludeNamesTree,
187+
builtIncluded: TJsonaUniqueIncluded = {}
187188
): void {
188189
if (!includeTree || !Object.keys(includeTree).length) {
189190
return;
@@ -217,9 +218,9 @@ export class ModelsSerializer implements IModelsSerializer {
217218
}
218219

219220
buildIncludedItem(
220-
relationModel: TJsonaModel,
221-
subIncludeTree: TJsonaNormalizedIncludeNamesTree,
222-
builtIncluded: TJsonaUniqueIncluded
221+
relationModel: TJsonaModel,
222+
subIncludeTree: TJsonaNormalizedIncludeNamesTree,
223+
builtIncluded: TJsonaUniqueIncluded
223224
) {
224225
const id = this.propertiesMapper.getId(relationModel);
225226
const type = this.propertiesMapper.getType(relationModel);

0 commit comments

Comments
 (0)