esm conversion for solid-type-index

main
Jackson Morgan 4 months ago
parent 5769b1aab2
commit b84a5905f3
  1. 3
      package-lock.json
  2. 7
      packages/solid-type-index/jest.config.js
  3. 1
      packages/solid-type-index/jest.setup.ts
  4. 27
      packages/solid-type-index/package.json
  5. 5
      packages/solid-type-index/src/setTypeIndex.ts
  6. 42
      packages/solid-type-index/test/General.test.tsx
  7. 4
      packages/solid-type-index/test/configs/components-config/unauthenticatedServer.json
  8. 0
      packages/solid-type-index/test/configs/solid-css-seed.json
  9. 0
      packages/solid-type-index/test/configs/template/wac/.acl.hbs
  10. 0
      packages/solid-type-index/test/configs/template/wac/profile/card.acl.hbs
  11. 71
      packages/solid-type-index/test/fileData.ts
  12. 7
      packages/solid-type-index/test/test-server/runServer.ts
  13. 39
      packages/solid-type-index/test/test-server/solidServer.helper.ts
  14. 8
      packages/solid-type-index/tsconfig.build.json
  15. 10
      packages/solid-type-index/tsconfig.cjs.json
  16. 11
      packages/solid-type-index/tsconfig.esm.json
  17. 9
      packages/solid-type-index/vitest.config.js

3
package-lock.json generated

@ -31264,8 +31264,6 @@
"@rdfjs/types": "^1.0.1",
"@testing-library/react": "^14.1.2",
"start-server-and-test": "^2.0.3",
"ts-node": "^10.9.2",
"tsx": "^4.19.4",
"whatwg-fetch": "^3.6.20"
}
},
@ -31395,6 +31393,7 @@
},
"devDependencies": {
"@ldo/rdf-utils": "^1.0.0-alpha.9",
"@ldo/test-solid-server": "^1.0.0-alpha.9",
"@rdfjs/types": "^1.0.1",
"@testing-library/react": "^14.1.2",
"jest-environment-jsdom": "^29.7.0",

@ -1,7 +0,0 @@
const sharedConfig = require("../../jest.config.js");
module.exports = {
...sharedConfig,
rootDir: "./",
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/jest.setup.ts"],
};

@ -1 +0,0 @@
import "@inrupt/jest-jsdom-polyfills";

@ -2,18 +2,26 @@
"name": "@ldo/solid-type-index",
"version": "1.0.0-alpha.9",
"description": "Solid Type Index support for LDO",
"main": "dist/index.js",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"watch": "tsc --watch",
"test": "npm run test:integration",
"test:watch": "jest --watch",
"build": "rimraf dist && npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:esm": "tsc --project tsconfig.esm.json",
"test": "vitest run --coverage",
"prepublishOnly": "npm run test && npm run build",
"build:ldo": "ldo build --input src/.shapes --output src/.ldo",
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern",
"test:integration": "start-server-and-test start-test-server http://localhost:3003 start-integration-test",
"start-test-server": "ts-node ./test/test-server/runServer.ts",
"start-integration-test": "jest --coverage"
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern"
},
"repository": {
"type": "git",
@ -27,6 +35,7 @@
"homepage": "https://github.com/o-development/ldo/tree/main/packages/solid-react#readme",
"devDependencies": {
"@ldo/rdf-utils": "^1.0.0-alpha.9",
"@ldo/test-solid-server": "^1.0.0-alpha.9",
"@rdfjs/types": "^1.0.1",
"@testing-library/react": "^14.1.2",
"jest-environment-jsdom": "^29.7.0",

@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { v4 } from "uuid";
$1$2.js$3
import { FOR_CLASS, RDF_TYPE, TYPE_REGISTRATION } from "./constants.js";
import { guaranteeOptions, type Options } from "./util/Options.js";
import { namedNode, quad } from "@rdfjs/data-model";
@ -16,6 +15,10 @@ import type {
SolidLeafUri,
} from "@ldo/connected-solid";
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
import {
TypeIndexDocumentShapeType,
TypeRegistrationShapeType,
} from "./.ldo/typeIndex.shapeTypes.js";
/**
* =============================================================================

@ -1,4 +1,5 @@
import {
fileData,
MY_BOOKMARKS_1_URI,
MY_BOOKMARKS_2_URI,
PRIVATE_TYPE_INDEX_URI,
@ -6,9 +7,8 @@ import {
ROOT_CONTAINER,
setupEmptyTypeIndex,
setupFullTypeIndex,
setUpServer,
WEB_ID,
} from "./setUpServer.js";
} from "./fileData.js";
import { getInstanceUris, getTypeRegistrations } from "../src/getTypeIndex.js";
import {
addRegistration,
@ -19,19 +19,43 @@ import { TypeIndexProfileShapeType } from "../src/.ldo/profile.shapeTypes.js";
import { namedNode } from "@rdfjs/dataset";
import { INSTANCE } from "../src/constants.js";
import { createSolidLdoDataset } from "@ldo/connected-solid";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { setupServer } from "@ldo/test-solid-server";
import { it, expect, describe, afterEach } from "vitest";
// Use an increased timeout, since the CSS server takes too much setup time.
jest.setTimeout(40_000);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const __dirname = dirname(fileURLToPath(import.meta.url));
const ADDRESS_BOOK = "http://www.w3.org/2006/vcard/ns#AddressBook";
const BOOKMARK = "http://www.w3.org/2002/01/bookmark#Bookmark";
const EXAMPLE_THING = "https://example.com/ExampleThing";
describe("General Tests", () => {
const s = setUpServer();
const s = setupServer(
3003,
fileData,
join(
__dirname,
"configs",
"components-config",
"unauthenticatedServer.json",
),
);
afterEach(async () => {
await Promise.all([
await s.authFetch(WEB_ID, { method: "DELETE" }),
await s.authFetch(PUBLIC_TYPE_INDEX_URI, { method: "DELETE" }),
await s.authFetch(PRIVATE_TYPE_INDEX_URI, { method: "DELETE" }),
await s.authFetch(MY_BOOKMARKS_1_URI, { method: "DELETE" }),
await s.authFetch(MY_BOOKMARKS_2_URI, { method: "DELETE" }),
]);
});
it("gets the current typeindex", async () => {
await setupFullTypeIndex(s);
await setupFullTypeIndex(s.authFetch);
const solidLdoDataset = createSolidLdoDataset();
const typeRegistrations = await getTypeRegistrations(WEB_ID, {
@ -67,7 +91,7 @@ describe("General Tests", () => {
});
it("initializes the type index", async () => {
await setupEmptyTypeIndex(s);
await setupEmptyTypeIndex(s.authFetch);
const solidLdoDataset = createSolidLdoDataset();
@ -84,7 +108,7 @@ describe("General Tests", () => {
});
it("Adds to the typeIndex", async () => {
await setupFullTypeIndex(s);
await setupFullTypeIndex(s.authFetch);
const solidLdoDataset = createSolidLdoDataset();
@ -125,7 +149,7 @@ describe("General Tests", () => {
});
it("Removes from the typeIndex", async () => {
await setupFullTypeIndex(s);
await setupFullTypeIndex(s.authFetch);
const solidLdoDataset = createSolidLdoDataset();

@ -45,8 +45,8 @@
},
"overrideParameters": {
"@type": "StaticFolderGenerator",
"templateFolder": "./test/test-server/configs/template"
"templateFolder": "./test/configs/template"
}
}
]
}
}

@ -1,4 +1,5 @@
import fetch from "cross-fetch";
import type fetch from "cross-fetch";
import type { ResourceInfo } from "@ldo/test-solid-server";
export const SERVER_DOMAIN = process.env.SERVER || "http://localhost:3003/";
export const ROOT_ROUTE = process.env.ROOT_CONTAINER || "example/";
@ -45,18 +46,16 @@ export const PRIVATE_TYPE_INDEX_TTL = `@prefix solid: <http://www.w3.org/ns/soli
solid:forClass bk:Bookmark;
solid:instanceContainer <${ROOT_CONTAINER}myBookmarks/>.`;
export interface SetUpServerReturn {
authFetch: typeof fetch;
fetchMock: jest.Mock<
Promise<Response>,
[input: RequestInfo | URL, init?: RequestInit | undefined]
>;
}
export const fileData: ResourceInfo = {
slug: "myBookmarks/",
isContainer: true,
contains: [],
};
export async function setupFullTypeIndex(s: SetUpServerReturn) {
export async function setupFullTypeIndex(authFetch: typeof fetch) {
// Create a new document called sample.ttl
await s.authFetch(WEB_ID, { method: "DELETE" });
await s.authFetch(ROOT_CONTAINER, {
await authFetch(WEB_ID, { method: "DELETE" });
await authFetch(ROOT_CONTAINER, {
method: "POST",
headers: {
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
@ -64,17 +63,17 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) {
},
});
await Promise.all([
s.authFetch(PROFILE_CONTAINER, {
authFetch(PROFILE_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "card.ttl" },
body: PROFILE_TTL,
}),
s.authFetch(PROFILE_CONTAINER, {
authFetch(PROFILE_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "publicTypeIndex.ttl" },
body: PUBLIC_TYPE_INDEX_TTL,
}),
s.authFetch(PROFILE_CONTAINER, {
authFetch(PROFILE_CONTAINER, {
method: "POST",
headers: {
"content-type": "text/turtle",
@ -82,12 +81,12 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) {
},
body: PRIVATE_TYPE_INDEX_TTL,
}),
s.authFetch(MY_BOOKMARKS_CONTAINER, {
authFetch(MY_BOOKMARKS_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "bookmark1.ttl" },
body: "",
}),
s.authFetch(MY_BOOKMARKS_CONTAINER, {
authFetch(MY_BOOKMARKS_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "bookmark2.ttl" },
body: "",
@ -95,10 +94,10 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) {
]);
}
export async function setupEmptyTypeIndex(s: SetUpServerReturn) {
export async function setupEmptyTypeIndex(authFetch: typeof fetch) {
// Create a new document called sample.ttl
await s.authFetch(WEB_ID, { method: "DELETE" });
await s.authFetch(ROOT_CONTAINER, {
await authFetch(WEB_ID, { method: "DELETE" });
await authFetch(ROOT_CONTAINER, {
method: "POST",
headers: {
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
@ -106,48 +105,20 @@ export async function setupEmptyTypeIndex(s: SetUpServerReturn) {
},
});
await Promise.all([
s.authFetch(PROFILE_CONTAINER, {
authFetch(PROFILE_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "card.ttl" },
body: "",
}),
s.authFetch(MY_BOOKMARKS_CONTAINER, {
authFetch(MY_BOOKMARKS_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "bookmark1.ttl" },
body: "",
}),
s.authFetch(MY_BOOKMARKS_CONTAINER, {
authFetch(MY_BOOKMARKS_CONTAINER, {
method: "POST",
headers: { "content-type": "text/turtle", slug: "bookmark2.ttl" },
body: "",
}),
]);
}
export function setUpServer(): SetUpServerReturn {
// Ignore to build s
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const s: SetUpServerReturn = {};
beforeAll(async () => {
// s.authFetch = await getAuthenticatedFetch();
s.authFetch = fetch;
});
beforeEach(async () => {
s.fetchMock = jest.fn(s.authFetch);
});
afterEach(async () => {
await Promise.all([
await s.authFetch(WEB_ID, { method: "DELETE" }),
await s.authFetch(PUBLIC_TYPE_INDEX_URI, { method: "DELETE" }),
await s.authFetch(PRIVATE_TYPE_INDEX_URI, { method: "DELETE" }),
await s.authFetch(MY_BOOKMARKS_1_URI, { method: "DELETE" }),
await s.authFetch(MY_BOOKMARKS_2_URI, { method: "DELETE" }),
]);
});
return s;
}

@ -1,7 +0,0 @@
import { createApp } from "./solidServer.helper.js";
async function run() {
const app = await createApp();
await app.start();
}
run();

@ -1,39 +0,0 @@
// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9
import * as path from "path";
import type { App } from "@solid/community-server";
import { AppRunner, resolveModulePath } from "@solid/community-server";
export async function createApp(): Promise<App> {
if (process.env.SERVER) {
return {
start: () => {},
stop: () => {},
} as App;
}
const appRunner = new AppRunner();
return appRunner.create({
loaderProperties: {
mainModulePath: resolveModulePath(""),
typeChecking: false,
},
config: path.join(
__dirname,
"configs",
"components-config",
"unauthenticatedServer.json",
),
variableBindings: {},
shorthand: {
port: 3_003,
loggingLevel: "off",
seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"),
},
});
}
export interface ISecretData {
id: string;
secret: string;
}

@ -1,8 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"lib": ["dom"]
},
"include": ["./src"]
}

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.cjs.json",
"compilerOptions": {
"outDir": "./dist/cjs",
"rootDir": "./src"
},
"include": [
"src"
]
}

@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"outDir": "./dist/esm",
"rootDir": "./src",
"declarationDir": "./dist/types"
},
"include": [
"src"
]
}

@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "istanbul",
},
},
});
Loading…
Cancel
Save