Comparing version 1.11.0 to 1.11.1
{ | ||
".": "1.11.0" | ||
".": "1.11.1" | ||
} |
# Changelog | ||
## [1.11.1](https://github.com/mathematic-inc/ts-japi/compare/v1.11.0...v1.11.1) (2024-04-17) | ||
### Bug Fixes | ||
* correctly serialize input array as array ([#84](https://github.com/mathematic-inc/ts-japi/issues/84)) ([37becd6](https://github.com/mathematic-inc/ts-japi/commit/37becd6ff307cf9ac1e47f1ec40c3e3e9ff09c90)) | ||
## [1.11.0](https://github.com/mathematic-inc/ts-japi/compare/v1.10.1...v1.11.0) (2024-04-08) | ||
@@ -4,0 +11,0 @@ |
@@ -16,5 +16,5 @@ import { DataDocument } from '../interfaces/json-api.interface'; | ||
createResource(data: PrimaryType, options?: Partial<SerializerOptions<PrimaryType>>, helpers?: Helpers<PrimaryType>, relatorDataCache?: Map<Relator<any>, Dictionary<any>[]>): Promise<Resource<PrimaryType>>; | ||
private serializeSingle; | ||
private serializeType; | ||
private getSerializerForData; | ||
} | ||
//# sourceMappingURL=polymorphic-serialiser.d.ts.map |
@@ -17,4 +17,12 @@ "use strict"; | ||
if (Array.isArray(data)) { | ||
const documents = await Promise.all(data.map((d) => { | ||
return this.serializeSingle(d, options); | ||
const documents = await Promise.all(Object.values(data.reduce((acc, d) => { | ||
// group data by type | ||
const type = d[this.key]; | ||
if (!acc[type]) { | ||
acc[type] = []; | ||
} | ||
acc[type].push(d); | ||
return acc; | ||
}, {})).map((d) => { | ||
return this.serializeType(d, options); | ||
})); | ||
@@ -31,3 +39,3 @@ return documents.reduce((result, document) => { | ||
else if (data) { | ||
return this.serializeSingle(data, options); | ||
return this.serializeType(data, options); | ||
} | ||
@@ -50,4 +58,4 @@ return Object.values(this.serialisers)[0].serialize(data, options); | ||
} | ||
async serializeSingle(data, options) { | ||
const serializer = this.getSerializerForData(data); | ||
async serializeType(data, options) { | ||
const serializer = this.getSerializerForData(Array.isArray(data) ? data[0] : data); | ||
if (serializer) { | ||
@@ -54,0 +62,0 @@ return serializer.serialize(data, options); |
{ | ||
"name": "ts-japi", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"description": "A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234816
3475