Skip to content

Commit

Permalink
fix: use @types/node buffer type rather than lib.dom.ts (#1979)
Browse files Browse the repository at this point in the history
* fix: use @types/node buffer type rather than lib.dom.ts

As discussed in microsoft/TypeScript#53668
the @types/node definition of a buffer is looser and hence we should
use that in order to be compaible with web buffer types and node
buffer types

* chore: run lint:fix

* chore: test saveFileInContainer for buffers

* chore: test buffers on overwriteFile

* chore: don't test blob on node 14

* chore: update changelog for new buffer definition

* Update e2e/node/resource.test.ts

Co-authored-by: Zwifi <nseydoux@inrupt.com>

* Update CHANGELOG.md

Co-authored-by: Zwifi <nseydoux@inrupt.com>

* chore: cleanup tests from review

* chore: remove unecessary type casting

---------

Co-authored-by: Zwifi <nseydoux@inrupt.com>
  • Loading branch information
jeswr and NSeydoux authored May 10, 2023
1 parent 82cde5b commit dabf1a1
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 232 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ The following changes are pending, and will be applied on the next major release

The following changes have been implemented but not released yet:

### Bugfixes

- `Buffer` type: As discussed in microsoft/TypeScript#53668 the
@types/node definition of a buffer is looser than the DOM one (the latter being TS' default), and hence we now
use that in order to be compatible with web buffer types and node
buffer types.

## [1.28.0] - 2023-05-09

### New feature
Expand Down
41 changes: 41 additions & 0 deletions e2e/node/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getPodRoot,
createFetch,
} from "@inrupt/internal-test-env";
import { Buffer as NodeBuffer, Blob } from "buffer";
import {
getSolidDataset,
setThing,
Expand Down Expand Up @@ -151,6 +152,46 @@ describe("Authenticated end-to-end", () => {
await deleteFile(fileUrl, fetchOptions);
});

it("can create, delete, and differentiate between RDF and non-RDF Resources using a node Buffer", async () => {
const fileUrl = `${sessionResource}.txt`;

const sessionFile = await overwriteFile(
fileUrl,
NodeBuffer.from("test"),
fetchOptions
);
const sessionDataset = await getSolidDataset(sessionResource, fetchOptions);

expect(isRawData(sessionDataset)).toBe(false);
expect(isRawData(sessionFile)).toBe(true);

await deleteFile(fileUrl, fetchOptions);
});

// Blob isn't available in Node 14
it("can create, delete, and differentiate between RDF and non-RDF Resources using a Blob", async () => {
const fileUrl = `${sessionResource}.txt`;

const sessionFile = await overwriteFile(
fileUrl,
// We need to type cast because the buffer definition
// of Blob does not have the prototype property expected
// by the lib.dom.ts
new Blob(["test"]) as unknown as globalThis.Blob,
fetchOptions
);
const sessionDataset = await getSolidDataset(sessionResource, fetchOptions);

// Eslint isn't detecting the fact that this is inside an it statement
// because of the conditional.
// eslint-disable-next-line jest/no-standalone-expect
expect(isRawData(sessionDataset)).toBe(false);
// eslint-disable-next-line jest/no-standalone-expect
expect(isRawData(sessionFile)).toBe(true);

await deleteFile(fileUrl, fetchOptions);
});

it("can create and remove Containers", async () => {
const containerUrl = `${pod}solid-client-tests/node/container-test/container1-${session.info.sessionId}/`;
const containerContainerUrl = `${pod}solid-client-tests/node/container-test/`;
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"@inrupt/universal-fetch": "^1.0.1",
"@rdfjs/dataset": "^1.1.0",
"@types/rdfjs__dataset": "^1.0.4",
"buffer": "^6.0.3",
"http-link-header": "^1.1.0",
"jsonld-context-parser": "^2.3.0",
"jsonld-streaming-parser": "^3.2.0",
Expand Down
Loading

1 comment on commit dabf1a1

@vercel
Copy link

@vercel vercel bot commented on dabf1a1 May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solid-client-js – ./

solid-client-js-inrupt.vercel.app
solid-client-js-git-main-inrupt.vercel.app
solid-client.vercel.app

Please sign in to comment.