Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import '@testing-library/jest-dom';
import { TextEncoder } from 'util';
import { TextEncoder, TextDecoder } from 'util';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Request } from 'node-fetch';

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder as any;
global.Request = Request as any;
2 changes: 1 addition & 1 deletion src/hydra/dataProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Transform a React Admin request to an Hydra request', () => {
perPage: 30,
},
sort: {
order: '',
order: 'ASC',
field: '',
},
filter: {
Expand Down
2 changes: 1 addition & 1 deletion src/hydra/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ function dataProvider(
page: 1,
},
filter: { id: params.ids },
sort: { field: '', order: '' },
sort: { field: '', order: 'ASC' },
}).then(({ data }) => ({ data }));
}

Expand Down
23 changes: 15 additions & 8 deletions src/hydra/fetchHydra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getDocumentationUrlFromHeaders,
} from '@api-platform/api-doc-parser';
import jsonld from 'jsonld';
import type { NodeObject } from 'jsonld';
import type { ContextDefinition, NodeObject } from 'jsonld';
import type { JsonLdObj } from 'jsonld/jsonld-spec';
import type { HttpClientOptions, HydraHttpClientResponse } from '../types.js';

Expand Down Expand Up @@ -40,21 +40,28 @@ function fetchHydra(

delete (body as NodeObject).trace;

const documentLoader = (input: string) =>
fetchJsonLd(input, authOptions).then((response) => {
const documentLoader = (input: string) => {
const loaderOptions = authOptions;
loaderOptions.method = 'GET';
delete loaderOptions.body;

return fetchJsonLd(input, loaderOptions).then((response) => {
if (!('body' in response)) {
throw new Error(
'An empty response was received when expanding JSON-LD error document.',
);
}
return response;
});
};

return documentLoader(getDocumentationUrlFromHeaders(headers))
.then((response) =>
jsonld.expand(body, {
expandContext: response.document as ContextDefinition,
}),
)

return jsonld
.expand(body, {
base: getDocumentationUrlFromHeaders(headers),
documentLoader,
})
.then((json) =>
Promise.reject(
new HttpError(
Expand Down
32 changes: 16 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,22 @@ export type ApiPlatformAdminDataProviderTypeParams<T extends DataProviderType> =
T extends typeof GET_LIST
? ApiPlatformAdminGetListParams
: T extends typeof GET_ONE
? ApiPlatformAdminGetOneParams
: T extends typeof GET_MANY
? ApiPlatformAdminGetManyParams
: T extends typeof GET_MANY_REFERENCE
? ApiPlatformAdminGetManyReferenceParams
: T extends typeof UPDATE
? ApiPlatformAdminUpdateParams
: T extends typeof UPDATE_MANY
? ApiPlatformAdminUpdateManyParams
: T extends typeof CREATE
? ApiPlatformAdminCreateParams
: T extends typeof DELETE
? ApiPlatformAdminDeleteParams
: T extends typeof DELETE_MANY
? ApiPlatformAdminDeleteManyParams
: never;
? ApiPlatformAdminGetOneParams
: T extends typeof GET_MANY
? ApiPlatformAdminGetManyParams
: T extends typeof GET_MANY_REFERENCE
? ApiPlatformAdminGetManyReferenceParams
: T extends typeof UPDATE
? ApiPlatformAdminUpdateParams
: T extends typeof UPDATE_MANY
? ApiPlatformAdminUpdateManyParams
: T extends typeof CREATE
? ApiPlatformAdminCreateParams
: T extends typeof DELETE
? ApiPlatformAdminDeleteParams
: T extends typeof DELETE_MANY
? ApiPlatformAdminDeleteManyParams
: never;

export interface ApiPlatformAdminDataProviderFactoryParams {
entrypoint: string;
Expand Down