@ldo/test-solid-server 1.0.0-alpha.51 → 1.0.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/{authFetch.mjs → authFetch.js} +1 -2
  2. package/dist/authFetch.js.map +1 -0
  3. package/dist/{createServer.d.cts → createServer.d.ts} +1 -1
  4. package/dist/createServer.d.ts.map +1 -0
  5. package/dist/{createServer.mjs → createServer.js} +1 -1
  6. package/dist/createServer.js.map +1 -0
  7. package/dist/index.d.ts +4 -0
  8. package/dist/index.js +4 -0
  9. package/dist/{resourceUtils.d.cts → resourceUtils.d.ts} +1 -1
  10. package/dist/resourceUtils.d.ts.map +1 -0
  11. package/dist/{resourceUtils.mjs → resourceUtils.js} +1 -1
  12. package/dist/resourceUtils.js.map +1 -0
  13. package/dist/{setupTestServer.d.mts → setupTestServer.d.ts} +2 -2
  14. package/dist/setupTestServer.d.ts.map +1 -0
  15. package/dist/{setupTestServer.mjs → setupTestServer.js} +4 -4
  16. package/dist/setupTestServer.js.map +1 -0
  17. package/package.json +10 -15
  18. package/src/authFetch.ts +0 -2
  19. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  20. package/dist/authFetch.cjs +0 -73
  21. package/dist/authFetch.mjs.map +0 -1
  22. package/dist/createServer.cjs +0 -30
  23. package/dist/createServer.d.cts.map +0 -1
  24. package/dist/createServer.d.mts +0 -7
  25. package/dist/createServer.d.mts.map +0 -1
  26. package/dist/createServer.mjs.map +0 -1
  27. package/dist/index.cjs +0 -8
  28. package/dist/index.d.cts +0 -4
  29. package/dist/index.d.mts +0 -4
  30. package/dist/index.mjs +0 -4
  31. package/dist/resourceUtils.cjs +0 -27
  32. package/dist/resourceUtils.d.cts.map +0 -1
  33. package/dist/resourceUtils.d.mts +0 -20
  34. package/dist/resourceUtils.d.mts.map +0 -1
  35. package/dist/resourceUtils.mjs.map +0 -1
  36. package/dist/setupTestServer.cjs +0 -56
  37. package/dist/setupTestServer.d.cts +0 -14
  38. package/dist/setupTestServer.d.cts.map +0 -1
  39. package/dist/setupTestServer.d.mts.map +0 -1
  40. package/dist/setupTestServer.mjs.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import { buildAuthenticatedFetch, createDpopHeader, generateDpopKeyPair } from "@inrupt/solid-client-authn-core";
2
- import fetch from "cross-fetch";
3
2
  //#region src/authFetch.ts
4
3
  const config = {
5
4
  podName: "example",
@@ -70,4 +69,4 @@ async function generateAuthFetch(port) {
70
69
  //#endregion
71
70
  export { generateAuthFetch };
72
71
 
73
- //# sourceMappingURL=authFetch.mjs.map
72
+ //# sourceMappingURL=authFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authFetch.js","names":[],"sources":["../src/authFetch.ts"],"sourcesContent":["import type { KeyPair } from \"@inrupt/solid-client-authn-core\";\nimport {\n buildAuthenticatedFetch,\n createDpopHeader,\n generateDpopKeyPair,\n} from \"@inrupt/solid-client-authn-core\";\nconst config = {\n podName: \"example\",\n email: \"hello@example.com\",\n password: \"abc123\",\n};\n\nasync function reportError(response: Response) {\n if (response.status >= 400) {\n console.error(await response.text());\n }\n}\n\nasync function getAuthorization(port: number): Promise<string> {\n // First we request the account API controls to find out where we can log in\n const indexResponse = await fetch(`http://localhost:${port}/.account/`);\n const { controls } = await indexResponse.json();\n\n // And then we log in to the account API\n const response = await fetch(controls.password.login, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n email: config.email,\n password: config.password,\n }),\n });\n // This authorization value will be used to authenticate in the next step\n await reportError(response);\n const result = await response.json();\n return result.authorization;\n}\n\nasync function getSecret(\n port: number,\n authorization: string,\n): Promise<{ id: string; secret: string; resource: string }> {\n // Now that we are logged in, we need to request the updated controls from the server.\n // These will now have more values than in the previous example.\n const indexResponse = await fetch(`http://localhost:${port}/.account/`, {\n headers: { authorization: `CSS-Account-Token ${authorization}` },\n });\n const { controls } = await indexResponse.json();\n\n // Here we request the server to generate a token on our account\n const response = await fetch(controls.account.clientCredentials, {\n method: \"POST\",\n headers: {\n authorization: `CSS-Account-Token ${authorization}`,\n \"content-type\": \"application/json\",\n },\n // The name field will be used when generating the ID of your token.\n // The WebID field determines which WebID you will identify as when using the token.\n // Only WebIDs linked to your account can be used.\n body: JSON.stringify({\n name: \"my-token\",\n webId: `http://localhost:${port}/${config.podName}/profile/card#me`,\n }),\n });\n await reportError(response);\n // These are the identifier and secret of your token.\n // Store the secret somewhere safe as there is no way to request it again from the server!\n // The `resource` value can be used to delete the token at a later point in time.\n const response2 = await response.json();\n return response2;\n}\n\nasync function getAccessToken(\n port: number,\n id: string,\n secret: string,\n): Promise<{ accessToken: string; dpopKey: KeyPair }> {\n try {\n // A key pair is needed for encryption.\n // This function from `solid-client-authn` generates such a pair for you.\n const dpopKey = await generateDpopKeyPair();\n\n // These are the ID and secret generated in the previous step.\n // Both the ID and the secret need to be form-encoded.\n const authString = `${encodeURIComponent(id)}:${encodeURIComponent(\n secret,\n )}`;\n // This URL can be found by looking at the \"token_endpoint\" field at\n // http://localhost:PORT/.well-known/openid-configuration\n // if your server is hosted at http://localhost:3000/.\n const tokenUrl = `http://localhost:${port}/.oidc/token`;\n const response = await fetch(tokenUrl, {\n method: \"POST\",\n headers: {\n // The header needs to be in base64 encoding.\n authorization: `Basic ${Buffer.from(authString).toString(\"base64\")}`,\n \"content-type\": \"application/x-www-form-urlencoded\",\n dpop: await createDpopHeader(tokenUrl, \"POST\", dpopKey),\n },\n body: \"grant_type=client_credentials&scope=webid\",\n });\n await reportError(response);\n // This is the Access token that will be used to do an authenticated request to the server.\n // The JSON also contains an \"expires_in\" field in seconds,\n // which you can use to know when you need request a new Access token.\n const response2 = await response.json();\n return { accessToken: response2.access_token, dpopKey };\n } catch (err) {\n console.error(err);\n throw err;\n }\n}\n\nexport async function generateAuthFetch(port: number) {\n const authorization = await getAuthorization(port);\n const { id, secret } = await getSecret(port, authorization);\n const { accessToken, dpopKey } = await getAccessToken(port, id, secret);\n return await buildAuthenticatedFetch(accessToken, { dpopKey });\n}\n"],"mappings":";;AAMA,MAAM,SAAS;CACb,SAAS;CACT,OAAO;CACP,UAAU;CACX;AAED,eAAe,YAAY,UAAoB;AAC7C,KAAI,SAAS,UAAU,IACrB,SAAQ,MAAM,MAAM,SAAS,MAAM,CAAC;;AAIxC,eAAe,iBAAiB,MAA+B;CAG7D,MAAM,EAAE,aAAa,OAAM,MADC,MAAM,oBAAoB,KAAK,YAAY,EAC9B,MAAM;CAG/C,MAAM,WAAW,MAAM,MAAM,SAAS,SAAS,OAAO;EACpD,QAAQ;EACR,SAAS,EAAE,gBAAgB,oBAAoB;EAC/C,MAAM,KAAK,UAAU;GACnB,OAAO,OAAO;GACd,UAAU,OAAO;GAClB,CAAC;EACH,CAAC;AAEF,OAAM,YAAY,SAAS;AAE3B,SAAO,MADc,SAAS,MAAM,EACtB;;AAGhB,eAAe,UACb,MACA,eAC2D;CAM3D,MAAM,EAAE,aAAa,OAAM,MAHC,MAAM,oBAAoB,KAAK,aAAa,EACtE,SAAS,EAAE,eAAe,qBAAqB,iBAAiB,EACjE,CAAC,EACuC,MAAM;CAG/C,MAAM,WAAW,MAAM,MAAM,SAAS,QAAQ,mBAAmB;EAC/D,QAAQ;EACR,SAAS;GACP,eAAe,qBAAqB;GACpC,gBAAgB;GACjB;EAID,MAAM,KAAK,UAAU;GACnB,MAAM;GACN,OAAO,oBAAoB,KAAK,GAAG,OAAO,QAAQ;GACnD,CAAC;EACH,CAAC;AACF,OAAM,YAAY,SAAS;AAK3B,QAAO,MADiB,SAAS,MAAM;;AAIzC,eAAe,eACb,MACA,IACA,QACoD;AACpD,KAAI;EAGF,MAAM,UAAU,MAAM,qBAAqB;EAI3C,MAAM,aAAa,GAAG,mBAAmB,GAAG,CAAC,GAAG,mBAC9C,OACD;EAID,MAAM,WAAW,oBAAoB,KAAK;EAC1C,MAAM,WAAW,MAAM,MAAM,UAAU;GACrC,QAAQ;GACR,SAAS;IAEP,eAAe,SAAS,OAAO,KAAK,WAAW,CAAC,SAAS,SAAS;IAClE,gBAAgB;IAChB,MAAM,MAAM,iBAAiB,UAAU,QAAQ,QAAQ;IACxD;GACD,MAAM;GACP,CAAC;AACF,QAAM,YAAY,SAAS;AAK3B,SAAO;GAAE,cAAa,MADE,SAAS,MAAM,EACP;GAAc;GAAS;UAChD,KAAK;AACZ,UAAQ,MAAM,IAAI;AAClB,QAAM;;;AAIV,eAAsB,kBAAkB,MAAc;CAEpD,MAAM,EAAE,IAAI,WAAW,MAAM,UAAU,MAAM,MADjB,iBAAiB,KAAK,CACS;CAC3D,MAAM,EAAE,aAAa,YAAY,MAAM,eAAe,MAAM,IAAI,OAAO;AACvE,QAAO,MAAM,wBAAwB,aAAa,EAAE,SAAS,CAAC"}
@@ -4,4 +4,4 @@ import { App } from "@solid/community-server";
4
4
  declare function createApp(port: number, customConfigPath?: string): Promise<App>;
5
5
  //#endregion
6
6
  export { createApp };
7
- //# sourceMappingURL=createServer.d.cts.map
7
+ //# sourceMappingURL=createServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServer.d.ts","names":[],"sources":["../src/createServer.ts"],"mappings":";;;iBAYsB,SAAA,CACpB,IAAA,UACA,gBAAA,YACC,OAAA,CAAQ,GAAA"}
@@ -27,4 +27,4 @@ async function createApp(port, customConfigPath) {
27
27
  //#endregion
28
28
  export { createApp };
29
29
 
30
- //# sourceMappingURL=createServer.mjs.map
30
+ //# sourceMappingURL=createServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServer.js","names":["path"],"sources":["../src/createServer.ts"],"sourcesContent":["// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9\n\nimport * as path from \"path\";\nimport type { App } from \"@solid/community-server\";\nimport { AppRunner, resolveModulePath } from \"@solid/community-server\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport async function createApp(\n port: number,\n customConfigPath?: string,\n): Promise<App> {\n if (process.env.SERVER) {\n return {\n start: () => {},\n stop: () => {},\n } as App;\n }\n const appRunner = new AppRunner();\n\n return appRunner.create({\n loaderProperties: {\n mainModulePath: resolveModulePath(\"\"),\n typeChecking: false,\n },\n config: customConfigPath ?? resolveModulePath(\"config/file-root.json\"),\n variableBindings: {},\n shorthand: {\n port: port,\n loggingLevel: \"off\",\n seedConfig: path.join(__dirname, \"configs\", \"solid-css-seed.json\"),\n rootFilePath: path.join(__dirname, `./data${port}`),\n },\n });\n}\n"],"mappings":";;;;;AAUA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,eAAsB,UACpB,MACA,kBACc;AACd,KAAI,QAAQ,IAAI,OACd,QAAO;EACL,aAAa;EACb,YAAY;EACb;AAIH,QAAO,IAFe,WAEN,CAAC,OAAO;EACtB,kBAAkB;GAChB,gBAAgB,kBAAkB,GAAG;GACrC,cAAc;GACf;EACD,QAAQ,oBAAoB,kBAAkB,wBAAwB;EACtE,kBAAkB,EAAE;EACpB,WAAW;GACH;GACN,cAAc;GACd,YAAYA,OAAK,KAAK,WAAW,WAAW,sBAAsB;GAClE,cAAcA,OAAK,KAAK,WAAW,SAAS,OAAO;GACpD;EACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { createApp } from "./createServer.js";
2
+ import { ResourceInfo, cleanResources, initResources } from "./resourceUtils.js";
3
+ import { setupServer } from "./setupTestServer.js";
4
+ export { ResourceInfo, cleanResources, createApp, initResources, setupServer };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { createApp } from "./createServer.js";
2
+ import { cleanResources, initResources } from "./resourceUtils.js";
3
+ import { setupServer } from "./setupTestServer.js";
4
+ export { cleanResources, createApp, initResources, setupServer };
@@ -17,4 +17,4 @@ declare function initResources(rootUri: string, resourceInfo: ResourceInfo, auth
17
17
  declare function cleanResources(rootUri: string, resourceInfo: ResourceInfo, authFetch: typeof fetch): Promise<void>;
18
18
  //#endregion
19
19
  export { ResourceInfo, cleanResources, initResources };
20
- //# sourceMappingURL=resourceUtils.d.cts.map
20
+ //# sourceMappingURL=resourceUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceUtils.d.ts","names":[],"sources":["../src/resourceUtils.ts"],"mappings":";KAAY,YAAA,GAAe,aAAA,GAAgB,QAAA;AAAA,UAEjC,aAAA;EACR,IAAA;EACA,WAAA;EACA,aAAA;EACA,QAAA,GAAW,aAAA,GAAgB,QAAA;AAAA;AAAA,UAGnB,QAAA;EACR,IAAA;EACA,WAAA;EACA,IAAA;EACA,aAAA;EACA,QAAA;AAAA;AAAA,iBAGoB,aAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA;AAAA,iBA8BmB,cAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA"}
@@ -25,4 +25,4 @@ async function cleanResources(rootUri, resourceInfo, authFetch) {
25
25
  //#endregion
26
26
  export { cleanResources, initResources };
27
27
 
28
- //# sourceMappingURL=resourceUtils.mjs.map
28
+ //# sourceMappingURL=resourceUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceUtils.js","names":[],"sources":["../src/resourceUtils.ts"],"sourcesContent":["export type ResourceInfo = ContainerInfo | LeafInfo;\n\ninterface ContainerInfo {\n slug: string;\n isContainer: true;\n shouldNotInit?: boolean;\n contains: (ContainerInfo | LeafInfo)[];\n}\n\ninterface LeafInfo {\n slug: string;\n isContainer: false;\n data: string;\n shouldNotInit?: boolean;\n mimeType: string;\n}\n\nexport async function initResources(\n rootUri: string,\n resourceInfo: ResourceInfo,\n authFetch: typeof fetch,\n): Promise<void> {\n if (resourceInfo?.shouldNotInit) return;\n if (resourceInfo.isContainer) {\n await authFetch(rootUri, {\n method: \"POST\",\n headers: {\n link: '<http://www.w3.org/ns/ldp#Container>; rel=\"type\"',\n slug: resourceInfo.slug,\n },\n });\n await Promise.all(\n resourceInfo.contains.map((subResourceInfo) =>\n initResources(\n `${rootUri}${resourceInfo.slug}`,\n subResourceInfo,\n authFetch,\n ),\n ),\n );\n } else {\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"PUT\",\n headers: {\n \"content-type\": resourceInfo.mimeType,\n },\n body: resourceInfo.data,\n });\n }\n}\n\nexport async function cleanResources(\n rootUri: string,\n resourceInfo: ResourceInfo,\n authFetch: typeof fetch,\n): Promise<void> {\n if (resourceInfo.isContainer) {\n await Promise.all(\n resourceInfo.contains.map((subResourceInfo) =>\n cleanResources(\n `${rootUri}${resourceInfo.slug}`,\n subResourceInfo,\n authFetch,\n ),\n ),\n );\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"DELETE\",\n });\n } else {\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"DELETE\",\n });\n }\n}\n"],"mappings":";AAiBA,eAAsB,cACpB,SACA,cACA,WACe;AACf,KAAI,cAAc,cAAe;AACjC,KAAI,aAAa,aAAa;AAC5B,QAAM,UAAU,SAAS;GACvB,QAAQ;GACR,SAAS;IACP,MAAM;IACN,MAAM,aAAa;IACpB;GACF,CAAC;AACF,QAAM,QAAQ,IACZ,aAAa,SAAS,KAAK,oBACzB,cACE,GAAG,UAAU,aAAa,QAC1B,iBACA,UACD,CACF,CACF;OAED,OAAM,UAAU,GAAG,UAAU,aAAa,QAAQ;EAChD,QAAQ;EACR,SAAS,EACP,gBAAgB,aAAa,UAC9B;EACD,MAAM,aAAa;EACpB,CAAC;;AAIN,eAAsB,eACpB,SACA,cACA,WACe;AACf,KAAI,aAAa,aAAa;AAC5B,QAAM,QAAQ,IACZ,aAAa,SAAS,KAAK,oBACzB,eACE,GAAG,UAAU,aAAa,QAC1B,iBACA,UACD,CACF,CACF;AACD,QAAM,UAAU,GAAG,UAAU,aAAa,QAAQ,EAChD,QAAQ,UACT,CAAC;OAEF,OAAM,UAAU,GAAG,UAAU,aAAa,QAAQ,EAChD,QAAQ,UACT,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ResourceInfo } from "./resourceUtils.mjs";
1
+ import { ResourceInfo } from "./resourceUtils.js";
2
2
  import { App } from "@solid/community-server";
3
3
  import { MockedFunction } from "vitest";
4
4
 
@@ -11,4 +11,4 @@ declare function setupServer(port: number, resourceInfo: ResourceInfo, customCon
11
11
  };
12
12
  //#endregion
13
13
  export { setupServer };
14
- //# sourceMappingURL=setupTestServer.d.mts.map
14
+ //# sourceMappingURL=setupTestServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTestServer.d.ts","names":[],"sources":["../src/setupTestServer.ts"],"mappings":";;;;;iBA0BgB,WAAA,CACd,IAAA,UACA,YAAA,EAAc,YAAA,EACd,gBAAA,WACA,kBAAA;OAGO,GAAA;aACM,cAAA,EAEP,KAAA,EAAO,WAAA,GAAc,GAAA,EACrB,IAAA,GAAO,WAAA,iBACJ,OAAA,CAAQ,QAAA;oBAEG,KAAA"}
@@ -1,6 +1,6 @@
1
- import { createApp } from "./createServer.mjs";
2
- import { cleanResources, initResources } from "./resourceUtils.mjs";
3
- import { generateAuthFetch } from "./authFetch.mjs";
1
+ import { createApp } from "./createServer.js";
2
+ import { cleanResources, initResources } from "./resourceUtils.js";
3
+ import { generateAuthFetch } from "./authFetch.js";
4
4
  import path from "path";
5
5
  import { dirname } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -52,4 +52,4 @@ function setupServer(port, resourceInfo, customConfigPath, skipAuthentication) {
52
52
  //#endregion
53
53
  export { setupServer };
54
54
 
55
- //# sourceMappingURL=setupTestServer.mjs.map
55
+ //# sourceMappingURL=setupTestServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTestServer.js","names":[],"sources":["../src/setupTestServer.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { App } from \"@solid/community-server\";\nimport { createApp } from \"./createServer\";\nimport path from \"path\";\nimport type { ResourceInfo } from \"./resourceUtils\";\nimport { cleanResources, initResources } from \"./resourceUtils\";\nimport { generateAuthFetch } from \"./authFetch\";\nimport fs from \"fs/promises\";\nimport {\n beforeAll,\n afterAll,\n beforeEach,\n afterEach,\n vi,\n type MockedFunction,\n} from \"vitest\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\n// Use an increased timeout, since the CSS server takes too much setup time.\nvi.setConfig({ testTimeout: 40_000, hookTimeout: 40_000 });\n\nexport function setupServer(\n port: number,\n resourceInfo: ResourceInfo,\n customConfigPath?: string,\n skipAuthentication?: boolean,\n) {\n const data: {\n app: App;\n fetchMock: MockedFunction<\n (\n input: RequestInfo | URL,\n init?: RequestInit | undefined,\n ) => Promise<Response>\n >;\n authFetch: typeof fetch;\n rootUri: string;\n } = {\n rootUri: `http://localhost:${port}/`,\n } as any;\n\n let previousJestId: string | undefined;\n let previousNodeEnv: string | undefined;\n beforeAll(async () => {\n // Remove Jest ID so that community solid server doesn't use the Jest Import\n process.env.NODE_ENV = \"other_test\";\n // Start up the server\n data.app = await createApp(port, customConfigPath);\n await data.app.start();\n data.authFetch = skipAuthentication ? fetch : await generateAuthFetch(port);\n });\n\n afterAll(async () => {\n // We're potentially ignoring data clean up and server shutdown because\n // sometimes this doesn't work in CI.\n try {\n await Promise.race([\n data.app.stop?.(),\n new Promise((_, reject) =>\n setTimeout(() => reject(new Error(\"Shutdown timeout\")), 10000),\n ),\n ]);\n } catch (err) {\n console.warn(\"⚠️ Ignoring shutdown error in CI:\", (err as Error).message);\n }\n\n try {\n const testDataPath = path.join(__dirname, `./data${port}`);\n await fs.rm(testDataPath, { recursive: true, force: true });\n } catch (err) {\n console.warn(\n \"⚠️ Ignoring data cleanup error in CI:\",\n (err as Error).message,\n );\n }\n\n process.env.JEST_WORKER_ID = previousJestId;\n process.env.NODE_ENV = previousNodeEnv;\n });\n\n beforeEach(async () => {\n data.fetchMock = vi.fn(data.authFetch);\n // Create a new document called sample.ttl\n await initResources(data.rootUri, resourceInfo, data.authFetch);\n });\n\n afterEach(async () => {\n await cleanResources(data.rootUri, resourceInfo, data.authFetch);\n });\n\n return data;\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAGzD,GAAG,UAAU;CAAE,aAAa;CAAQ,aAAa;CAAQ,CAAC;AAE1D,SAAgB,YACd,MACA,cACA,kBACA,oBACA;CACA,MAAM,OAUF,EACF,SAAS,oBAAoB,KAAK,IACnC;CAED,IAAI;CACJ,IAAI;AACJ,WAAU,YAAY;AAEpB,UAAQ,IAAI,WAAW;AAEvB,OAAK,MAAM,MAAM,UAAU,MAAM,iBAAiB;AAClD,QAAM,KAAK,IAAI,OAAO;AACtB,OAAK,YAAY,qBAAqB,QAAQ,MAAM,kBAAkB,KAAK;GAC3E;AAEF,UAAS,YAAY;AAGnB,MAAI;AACF,SAAM,QAAQ,KAAK,CACjB,KAAK,IAAI,QAAQ,EACjB,IAAI,SAAS,GAAG,WACd,iBAAiB,uBAAO,IAAI,MAAM,mBAAmB,CAAC,EAAE,IAAM,CAC/D,CACF,CAAC;WACK,KAAK;AACZ,WAAQ,KAAK,qCAAsC,IAAc,QAAQ;;AAG3E,MAAI;GACF,MAAM,eAAe,KAAK,KAAK,WAAW,SAAS,OAAO;AAC1D,SAAM,GAAG,GAAG,cAAc;IAAE,WAAW;IAAM,OAAO;IAAM,CAAC;WACpD,KAAK;AACZ,WAAQ,KACN,yCACC,IAAc,QAChB;;AAGH,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI,WAAW;GACvB;AAEF,YAAW,YAAY;AACrB,OAAK,YAAY,GAAG,GAAG,KAAK,UAAU;AAEtC,QAAM,cAAc,KAAK,SAAS,cAAc,KAAK,UAAU;GAC/D;AAEF,WAAU,YAAY;AACpB,QAAM,eAAe,KAAK,SAAS,cAAc,KAAK,UAAU;GAChE;AAEF,QAAO"}
package/package.json CHANGED
@@ -1,28 +1,20 @@
1
1
  {
2
2
  "name": "@ldo/test-solid-server",
3
- "version": "1.0.0-alpha.51",
3
+ "version": "1.0.0-alpha.53",
4
4
  "description": "A solid server to be used in jest tests",
5
5
  "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.mts",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.mts",
13
- "default": "./dist/index.mjs"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/index.cjs"
18
- }
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
19
12
  },
20
13
  "./package.json": "./package.json"
21
14
  },
22
15
  "scripts": {
23
16
  "build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=8192 tsdown",
24
17
  "prepublishOnly": "npm run build",
25
- "copy-configs": "cp -r src/configs dist/cjs/configs && cp -r src/configs dist/esm/configs",
26
18
  "lint:check": "eslint src/** --no-error-on-unmatched-pattern",
27
19
  "lint": "npm run lint:check -- --fix",
28
20
  "remove-dist": "rimraf dist/"
@@ -39,15 +31,18 @@
39
31
  "homepage": "https://github.com/o-development/ldo/tree/main/packages/solid#readme",
40
32
  "dependencies": {
41
33
  "@inrupt/solid-client-authn-core": "3.0.0",
42
- "@solid/community-server": "8.0.0-alpha.0",
34
+ "@solid/community-server": "8.0.0-alpha.3",
43
35
  "cross-env": "^7.0.3"
44
36
  },
45
37
  "files": [
46
38
  "dist",
47
39
  "src"
48
40
  ],
41
+ "engines": {
42
+ "node": ">=20.19.0"
43
+ },
49
44
  "publishConfig": {
50
45
  "access": "public"
51
46
  },
52
- "gitHead": "59ce170c91a44ff43d59bb647fd7afd03daa4c66"
47
+ "gitHead": "4064165d9f3fbeadcb6b06b5e978771535bd3c56"
53
48
  }
package/src/authFetch.ts CHANGED
@@ -4,8 +4,6 @@ import {
4
4
  createDpopHeader,
5
5
  generateDpopKeyPair,
6
6
  } from "@inrupt/solid-client-authn-core";
7
- import fetch from "cross-fetch";
8
-
9
7
  const config = {
10
8
  podName: "example",
11
9
  email: "hello@example.com",
@@ -1,23 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- exports.__toESM = __toESM;
@@ -1,73 +0,0 @@
1
- const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
- let _inrupt_solid_client_authn_core = require("@inrupt/solid-client-authn-core");
3
- let cross_fetch = require("cross-fetch");
4
- cross_fetch = require_runtime.__toESM(cross_fetch, 1);
5
- //#region src/authFetch.ts
6
- const config = {
7
- podName: "example",
8
- email: "hello@example.com",
9
- password: "abc123"
10
- };
11
- async function reportError(response) {
12
- if (response.status >= 400) console.error(await response.text());
13
- }
14
- async function getAuthorization(port) {
15
- const { controls } = await (await (0, cross_fetch.default)(`http://localhost:${port}/.account/`)).json();
16
- const response = await (0, cross_fetch.default)(controls.password.login, {
17
- method: "POST",
18
- headers: { "content-type": "application/json" },
19
- body: JSON.stringify({
20
- email: config.email,
21
- password: config.password
22
- })
23
- });
24
- await reportError(response);
25
- return (await response.json()).authorization;
26
- }
27
- async function getSecret(port, authorization) {
28
- const { controls } = await (await (0, cross_fetch.default)(`http://localhost:${port}/.account/`, { headers: { authorization: `CSS-Account-Token ${authorization}` } })).json();
29
- const response = await (0, cross_fetch.default)(controls.account.clientCredentials, {
30
- method: "POST",
31
- headers: {
32
- authorization: `CSS-Account-Token ${authorization}`,
33
- "content-type": "application/json"
34
- },
35
- body: JSON.stringify({
36
- name: "my-token",
37
- webId: `http://localhost:${port}/${config.podName}/profile/card#me`
38
- })
39
- });
40
- await reportError(response);
41
- return await response.json();
42
- }
43
- async function getAccessToken(port, id, secret) {
44
- try {
45
- const dpopKey = await (0, _inrupt_solid_client_authn_core.generateDpopKeyPair)();
46
- const authString = `${encodeURIComponent(id)}:${encodeURIComponent(secret)}`;
47
- const tokenUrl = `http://localhost:${port}/.oidc/token`;
48
- const response = await (0, cross_fetch.default)(tokenUrl, {
49
- method: "POST",
50
- headers: {
51
- authorization: `Basic ${Buffer.from(authString).toString("base64")}`,
52
- "content-type": "application/x-www-form-urlencoded",
53
- dpop: await (0, _inrupt_solid_client_authn_core.createDpopHeader)(tokenUrl, "POST", dpopKey)
54
- },
55
- body: "grant_type=client_credentials&scope=webid"
56
- });
57
- await reportError(response);
58
- return {
59
- accessToken: (await response.json()).access_token,
60
- dpopKey
61
- };
62
- } catch (err) {
63
- console.error(err);
64
- throw err;
65
- }
66
- }
67
- async function generateAuthFetch(port) {
68
- const { id, secret } = await getSecret(port, await getAuthorization(port));
69
- const { accessToken, dpopKey } = await getAccessToken(port, id, secret);
70
- return await (0, _inrupt_solid_client_authn_core.buildAuthenticatedFetch)(accessToken, { dpopKey });
71
- }
72
- //#endregion
73
- exports.generateAuthFetch = generateAuthFetch;
@@ -1 +0,0 @@
1
- {"version":3,"file":"authFetch.mjs","names":[],"sources":["../src/authFetch.ts"],"sourcesContent":["import type { KeyPair } from \"@inrupt/solid-client-authn-core\";\nimport {\n buildAuthenticatedFetch,\n createDpopHeader,\n generateDpopKeyPair,\n} from \"@inrupt/solid-client-authn-core\";\nimport fetch from \"cross-fetch\";\n\nconst config = {\n podName: \"example\",\n email: \"hello@example.com\",\n password: \"abc123\",\n};\n\nasync function reportError(response: Response) {\n if (response.status >= 400) {\n console.error(await response.text());\n }\n}\n\nasync function getAuthorization(port: number): Promise<string> {\n // First we request the account API controls to find out where we can log in\n const indexResponse = await fetch(`http://localhost:${port}/.account/`);\n const { controls } = await indexResponse.json();\n\n // And then we log in to the account API\n const response = await fetch(controls.password.login, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n email: config.email,\n password: config.password,\n }),\n });\n // This authorization value will be used to authenticate in the next step\n await reportError(response);\n const result = await response.json();\n return result.authorization;\n}\n\nasync function getSecret(\n port: number,\n authorization: string,\n): Promise<{ id: string; secret: string; resource: string }> {\n // Now that we are logged in, we need to request the updated controls from the server.\n // These will now have more values than in the previous example.\n const indexResponse = await fetch(`http://localhost:${port}/.account/`, {\n headers: { authorization: `CSS-Account-Token ${authorization}` },\n });\n const { controls } = await indexResponse.json();\n\n // Here we request the server to generate a token on our account\n const response = await fetch(controls.account.clientCredentials, {\n method: \"POST\",\n headers: {\n authorization: `CSS-Account-Token ${authorization}`,\n \"content-type\": \"application/json\",\n },\n // The name field will be used when generating the ID of your token.\n // The WebID field determines which WebID you will identify as when using the token.\n // Only WebIDs linked to your account can be used.\n body: JSON.stringify({\n name: \"my-token\",\n webId: `http://localhost:${port}/${config.podName}/profile/card#me`,\n }),\n });\n await reportError(response);\n // These are the identifier and secret of your token.\n // Store the secret somewhere safe as there is no way to request it again from the server!\n // The `resource` value can be used to delete the token at a later point in time.\n const response2 = await response.json();\n return response2;\n}\n\nasync function getAccessToken(\n port: number,\n id: string,\n secret: string,\n): Promise<{ accessToken: string; dpopKey: KeyPair }> {\n try {\n // A key pair is needed for encryption.\n // This function from `solid-client-authn` generates such a pair for you.\n const dpopKey = await generateDpopKeyPair();\n\n // These are the ID and secret generated in the previous step.\n // Both the ID and the secret need to be form-encoded.\n const authString = `${encodeURIComponent(id)}:${encodeURIComponent(\n secret,\n )}`;\n // This URL can be found by looking at the \"token_endpoint\" field at\n // http://localhost:PORT/.well-known/openid-configuration\n // if your server is hosted at http://localhost:3000/.\n const tokenUrl = `http://localhost:${port}/.oidc/token`;\n const response = await fetch(tokenUrl, {\n method: \"POST\",\n headers: {\n // The header needs to be in base64 encoding.\n authorization: `Basic ${Buffer.from(authString).toString(\"base64\")}`,\n \"content-type\": \"application/x-www-form-urlencoded\",\n dpop: await createDpopHeader(tokenUrl, \"POST\", dpopKey),\n },\n body: \"grant_type=client_credentials&scope=webid\",\n });\n await reportError(response);\n // This is the Access token that will be used to do an authenticated request to the server.\n // The JSON also contains an \"expires_in\" field in seconds,\n // which you can use to know when you need request a new Access token.\n const response2 = await response.json();\n return { accessToken: response2.access_token, dpopKey };\n } catch (err) {\n console.error(err);\n throw err;\n }\n}\n\nexport async function generateAuthFetch(port: number) {\n const authorization = await getAuthorization(port);\n const { id, secret } = await getSecret(port, authorization);\n const { accessToken, dpopKey } = await getAccessToken(port, id, secret);\n return await buildAuthenticatedFetch(accessToken, { dpopKey });\n}\n"],"mappings":";;;AAQA,MAAM,SAAS;CACb,SAAS;CACT,OAAO;CACP,UAAU;CACX;AAED,eAAe,YAAY,UAAoB;AAC7C,KAAI,SAAS,UAAU,IACrB,SAAQ,MAAM,MAAM,SAAS,MAAM,CAAC;;AAIxC,eAAe,iBAAiB,MAA+B;CAG7D,MAAM,EAAE,aAAa,OAAM,MADC,MAAM,oBAAoB,KAAK,YAAY,EAC9B,MAAM;CAG/C,MAAM,WAAW,MAAM,MAAM,SAAS,SAAS,OAAO;EACpD,QAAQ;EACR,SAAS,EAAE,gBAAgB,oBAAoB;EAC/C,MAAM,KAAK,UAAU;GACnB,OAAO,OAAO;GACd,UAAU,OAAO;GAClB,CAAC;EACH,CAAC;AAEF,OAAM,YAAY,SAAS;AAE3B,SAAO,MADc,SAAS,MAAM,EACtB;;AAGhB,eAAe,UACb,MACA,eAC2D;CAM3D,MAAM,EAAE,aAAa,OAAM,MAHC,MAAM,oBAAoB,KAAK,aAAa,EACtE,SAAS,EAAE,eAAe,qBAAqB,iBAAiB,EACjE,CAAC,EACuC,MAAM;CAG/C,MAAM,WAAW,MAAM,MAAM,SAAS,QAAQ,mBAAmB;EAC/D,QAAQ;EACR,SAAS;GACP,eAAe,qBAAqB;GACpC,gBAAgB;GACjB;EAID,MAAM,KAAK,UAAU;GACnB,MAAM;GACN,OAAO,oBAAoB,KAAK,GAAG,OAAO,QAAQ;GACnD,CAAC;EACH,CAAC;AACF,OAAM,YAAY,SAAS;AAK3B,QAAO,MADiB,SAAS,MAAM;;AAIzC,eAAe,eACb,MACA,IACA,QACoD;AACpD,KAAI;EAGF,MAAM,UAAU,MAAM,qBAAqB;EAI3C,MAAM,aAAa,GAAG,mBAAmB,GAAG,CAAC,GAAG,mBAC9C,OACD;EAID,MAAM,WAAW,oBAAoB,KAAK;EAC1C,MAAM,WAAW,MAAM,MAAM,UAAU;GACrC,QAAQ;GACR,SAAS;IAEP,eAAe,SAAS,OAAO,KAAK,WAAW,CAAC,SAAS,SAAS;IAClE,gBAAgB;IAChB,MAAM,MAAM,iBAAiB,UAAU,QAAQ,QAAQ;IACxD;GACD,MAAM;GACP,CAAC;AACF,QAAM,YAAY,SAAS;AAK3B,SAAO;GAAE,cAAa,MADE,SAAS,MAAM,EACP;GAAc;GAAS;UAChD,KAAK;AACZ,UAAQ,MAAM,IAAI;AAClB,QAAM;;;AAIV,eAAsB,kBAAkB,MAAc;CAEpD,MAAM,EAAE,IAAI,WAAW,MAAM,UAAU,MAAM,MADjB,iBAAiB,KAAK,CACS;CAC3D,MAAM,EAAE,aAAa,YAAY,MAAM,eAAe,MAAM,IAAI,OAAO;AACvE,QAAO,MAAM,wBAAwB,aAAa,EAAE,SAAS,CAAC"}
@@ -1,30 +0,0 @@
1
- const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
- let path = require("path");
3
- path = require_runtime.__toESM(path, 1);
4
- let _solid_community_server = require("@solid/community-server");
5
- let node_path = require("node:path");
6
- let node_url = require("node:url");
7
- //#region src/createServer.ts
8
- const __dirname$1 = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
9
- async function createApp(port, customConfigPath) {
10
- if (process.env.SERVER) return {
11
- start: () => {},
12
- stop: () => {}
13
- };
14
- return new _solid_community_server.AppRunner().create({
15
- loaderProperties: {
16
- mainModulePath: (0, _solid_community_server.resolveModulePath)(""),
17
- typeChecking: false
18
- },
19
- config: customConfigPath ?? (0, _solid_community_server.resolveModulePath)("config/file-root.json"),
20
- variableBindings: {},
21
- shorthand: {
22
- port,
23
- loggingLevel: "off",
24
- seedConfig: path.join(__dirname$1, "configs", "solid-css-seed.json"),
25
- rootFilePath: path.join(__dirname$1, `./data${port}`)
26
- }
27
- });
28
- }
29
- //#endregion
30
- exports.createApp = createApp;
@@ -1 +0,0 @@
1
- {"version":3,"file":"createServer.d.cts","names":[],"sources":["../src/createServer.ts"],"mappings":";;;iBAYsB,SAAA,CACpB,IAAA,UACA,gBAAA,YACC,OAAA,CAAQ,GAAA"}
@@ -1,7 +0,0 @@
1
- import { App } from "@solid/community-server";
2
-
3
- //#region src/createServer.d.ts
4
- declare function createApp(port: number, customConfigPath?: string): Promise<App>;
5
- //#endregion
6
- export { createApp };
7
- //# sourceMappingURL=createServer.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createServer.d.mts","names":[],"sources":["../src/createServer.ts"],"mappings":";;;iBAYsB,SAAA,CACpB,IAAA,UACA,gBAAA,YACC,OAAA,CAAQ,GAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createServer.mjs","names":["path"],"sources":["../src/createServer.ts"],"sourcesContent":["// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9\n\nimport * as path from \"path\";\nimport type { App } from \"@solid/community-server\";\nimport { AppRunner, resolveModulePath } from \"@solid/community-server\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport async function createApp(\n port: number,\n customConfigPath?: string,\n): Promise<App> {\n if (process.env.SERVER) {\n return {\n start: () => {},\n stop: () => {},\n } as App;\n }\n const appRunner = new AppRunner();\n\n return appRunner.create({\n loaderProperties: {\n mainModulePath: resolveModulePath(\"\"),\n typeChecking: false,\n },\n config: customConfigPath ?? resolveModulePath(\"config/file-root.json\"),\n variableBindings: {},\n shorthand: {\n port: port,\n loggingLevel: \"off\",\n seedConfig: path.join(__dirname, \"configs\", \"solid-css-seed.json\"),\n rootFilePath: path.join(__dirname, `./data${port}`),\n },\n });\n}\n"],"mappings":";;;;;AAUA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,eAAsB,UACpB,MACA,kBACc;AACd,KAAI,QAAQ,IAAI,OACd,QAAO;EACL,aAAa;EACb,YAAY;EACb;AAIH,QAAO,IAFe,WAEN,CAAC,OAAO;EACtB,kBAAkB;GAChB,gBAAgB,kBAAkB,GAAG;GACrC,cAAc;GACf;EACD,QAAQ,oBAAoB,kBAAkB,wBAAwB;EACtE,kBAAkB,EAAE;EACpB,WAAW;GACH;GACN,cAAc;GACd,YAAYA,OAAK,KAAK,WAAW,WAAW,sBAAsB;GAClE,cAAcA,OAAK,KAAK,WAAW,SAAS,OAAO;GACpD;EACF,CAAC"}
package/dist/index.cjs DELETED
@@ -1,8 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_createServer = require("./createServer.cjs");
3
- const require_resourceUtils = require("./resourceUtils.cjs");
4
- const require_setupTestServer = require("./setupTestServer.cjs");
5
- exports.cleanResources = require_resourceUtils.cleanResources;
6
- exports.createApp = require_createServer.createApp;
7
- exports.initResources = require_resourceUtils.initResources;
8
- exports.setupServer = require_setupTestServer.setupServer;
package/dist/index.d.cts DELETED
@@ -1,4 +0,0 @@
1
- import { createApp } from "./createServer.cjs";
2
- import { ResourceInfo, cleanResources, initResources } from "./resourceUtils.cjs";
3
- import { setupServer } from "./setupTestServer.cjs";
4
- export { ResourceInfo, cleanResources, createApp, initResources, setupServer };
package/dist/index.d.mts DELETED
@@ -1,4 +0,0 @@
1
- import { createApp } from "./createServer.mjs";
2
- import { ResourceInfo, cleanResources, initResources } from "./resourceUtils.mjs";
3
- import { setupServer } from "./setupTestServer.mjs";
4
- export { ResourceInfo, cleanResources, createApp, initResources, setupServer };
package/dist/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { createApp } from "./createServer.mjs";
2
- import { cleanResources, initResources } from "./resourceUtils.mjs";
3
- import { setupServer } from "./setupTestServer.mjs";
4
- export { cleanResources, createApp, initResources, setupServer };
@@ -1,27 +0,0 @@
1
- //#region src/resourceUtils.ts
2
- async function initResources(rootUri, resourceInfo, authFetch) {
3
- if (resourceInfo?.shouldNotInit) return;
4
- if (resourceInfo.isContainer) {
5
- await authFetch(rootUri, {
6
- method: "POST",
7
- headers: {
8
- link: "<http://www.w3.org/ns/ldp#Container>; rel=\"type\"",
9
- slug: resourceInfo.slug
10
- }
11
- });
12
- await Promise.all(resourceInfo.contains.map((subResourceInfo) => initResources(`${rootUri}${resourceInfo.slug}`, subResourceInfo, authFetch)));
13
- } else await authFetch(`${rootUri}${resourceInfo.slug}`, {
14
- method: "PUT",
15
- headers: { "content-type": resourceInfo.mimeType },
16
- body: resourceInfo.data
17
- });
18
- }
19
- async function cleanResources(rootUri, resourceInfo, authFetch) {
20
- if (resourceInfo.isContainer) {
21
- await Promise.all(resourceInfo.contains.map((subResourceInfo) => cleanResources(`${rootUri}${resourceInfo.slug}`, subResourceInfo, authFetch)));
22
- await authFetch(`${rootUri}${resourceInfo.slug}`, { method: "DELETE" });
23
- } else await authFetch(`${rootUri}${resourceInfo.slug}`, { method: "DELETE" });
24
- }
25
- //#endregion
26
- exports.cleanResources = cleanResources;
27
- exports.initResources = initResources;
@@ -1 +0,0 @@
1
- {"version":3,"file":"resourceUtils.d.cts","names":[],"sources":["../src/resourceUtils.ts"],"mappings":";KAAY,YAAA,GAAe,aAAA,GAAgB,QAAA;AAAA,UAEjC,aAAA;EACR,IAAA;EACA,WAAA;EACA,aAAA;EACA,QAAA,GAAW,aAAA,GAAgB,QAAA;AAAA;AAAA,UAGnB,QAAA;EACR,IAAA;EACA,WAAA;EACA,IAAA;EACA,aAAA;EACA,QAAA;AAAA;AAAA,iBAGoB,aAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA;AAAA,iBA8BmB,cAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA"}
@@ -1,20 +0,0 @@
1
- //#region src/resourceUtils.d.ts
2
- type ResourceInfo = ContainerInfo | LeafInfo;
3
- interface ContainerInfo {
4
- slug: string;
5
- isContainer: true;
6
- shouldNotInit?: boolean;
7
- contains: (ContainerInfo | LeafInfo)[];
8
- }
9
- interface LeafInfo {
10
- slug: string;
11
- isContainer: false;
12
- data: string;
13
- shouldNotInit?: boolean;
14
- mimeType: string;
15
- }
16
- declare function initResources(rootUri: string, resourceInfo: ResourceInfo, authFetch: typeof fetch): Promise<void>;
17
- declare function cleanResources(rootUri: string, resourceInfo: ResourceInfo, authFetch: typeof fetch): Promise<void>;
18
- //#endregion
19
- export { ResourceInfo, cleanResources, initResources };
20
- //# sourceMappingURL=resourceUtils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resourceUtils.d.mts","names":[],"sources":["../src/resourceUtils.ts"],"mappings":";KAAY,YAAA,GAAe,aAAA,GAAgB,QAAA;AAAA,UAEjC,aAAA;EACR,IAAA;EACA,WAAA;EACA,aAAA;EACA,QAAA,GAAW,aAAA,GAAgB,QAAA;AAAA;AAAA,UAGnB,QAAA;EACR,IAAA;EACA,WAAA;EACA,IAAA;EACA,aAAA;EACA,QAAA;AAAA;AAAA,iBAGoB,aAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA;AAAA,iBA8BmB,cAAA,CACpB,OAAA,UACA,YAAA,EAAc,YAAA,EACd,SAAA,SAAkB,KAAA,GACjB,OAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resourceUtils.mjs","names":[],"sources":["../src/resourceUtils.ts"],"sourcesContent":["export type ResourceInfo = ContainerInfo | LeafInfo;\n\ninterface ContainerInfo {\n slug: string;\n isContainer: true;\n shouldNotInit?: boolean;\n contains: (ContainerInfo | LeafInfo)[];\n}\n\ninterface LeafInfo {\n slug: string;\n isContainer: false;\n data: string;\n shouldNotInit?: boolean;\n mimeType: string;\n}\n\nexport async function initResources(\n rootUri: string,\n resourceInfo: ResourceInfo,\n authFetch: typeof fetch,\n): Promise<void> {\n if (resourceInfo?.shouldNotInit) return;\n if (resourceInfo.isContainer) {\n await authFetch(rootUri, {\n method: \"POST\",\n headers: {\n link: '<http://www.w3.org/ns/ldp#Container>; rel=\"type\"',\n slug: resourceInfo.slug,\n },\n });\n await Promise.all(\n resourceInfo.contains.map((subResourceInfo) =>\n initResources(\n `${rootUri}${resourceInfo.slug}`,\n subResourceInfo,\n authFetch,\n ),\n ),\n );\n } else {\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"PUT\",\n headers: {\n \"content-type\": resourceInfo.mimeType,\n },\n body: resourceInfo.data,\n });\n }\n}\n\nexport async function cleanResources(\n rootUri: string,\n resourceInfo: ResourceInfo,\n authFetch: typeof fetch,\n): Promise<void> {\n if (resourceInfo.isContainer) {\n await Promise.all(\n resourceInfo.contains.map((subResourceInfo) =>\n cleanResources(\n `${rootUri}${resourceInfo.slug}`,\n subResourceInfo,\n authFetch,\n ),\n ),\n );\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"DELETE\",\n });\n } else {\n await authFetch(`${rootUri}${resourceInfo.slug}`, {\n method: \"DELETE\",\n });\n }\n}\n"],"mappings":";AAiBA,eAAsB,cACpB,SACA,cACA,WACe;AACf,KAAI,cAAc,cAAe;AACjC,KAAI,aAAa,aAAa;AAC5B,QAAM,UAAU,SAAS;GACvB,QAAQ;GACR,SAAS;IACP,MAAM;IACN,MAAM,aAAa;IACpB;GACF,CAAC;AACF,QAAM,QAAQ,IACZ,aAAa,SAAS,KAAK,oBACzB,cACE,GAAG,UAAU,aAAa,QAC1B,iBACA,UACD,CACF,CACF;OAED,OAAM,UAAU,GAAG,UAAU,aAAa,QAAQ;EAChD,QAAQ;EACR,SAAS,EACP,gBAAgB,aAAa,UAC9B;EACD,MAAM,aAAa;EACpB,CAAC;;AAIN,eAAsB,eACpB,SACA,cACA,WACe;AACf,KAAI,aAAa,aAAa;AAC5B,QAAM,QAAQ,IACZ,aAAa,SAAS,KAAK,oBACzB,eACE,GAAG,UAAU,aAAa,QAC1B,iBACA,UACD,CACF,CACF;AACD,QAAM,UAAU,GAAG,UAAU,aAAa,QAAQ,EAChD,QAAQ,UACT,CAAC;OAEF,OAAM,UAAU,GAAG,UAAU,aAAa,QAAQ,EAChD,QAAQ,UACT,CAAC"}
@@ -1,56 +0,0 @@
1
- const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
- const require_createServer = require("./createServer.cjs");
3
- const require_resourceUtils = require("./resourceUtils.cjs");
4
- const require_authFetch = require("./authFetch.cjs");
5
- let path = require("path");
6
- path = require_runtime.__toESM(path, 1);
7
- let node_path = require("node:path");
8
- let node_url = require("node:url");
9
- let fs_promises = require("fs/promises");
10
- fs_promises = require_runtime.__toESM(fs_promises, 1);
11
- let vitest = require("vitest");
12
- //#region src/setupTestServer.ts
13
- const __dirname$1 = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
14
- vitest.vi.setConfig({
15
- testTimeout: 4e4,
16
- hookTimeout: 4e4
17
- });
18
- function setupServer(port, resourceInfo, customConfigPath, skipAuthentication) {
19
- const data = { rootUri: `http://localhost:${port}/` };
20
- let previousJestId;
21
- let previousNodeEnv;
22
- (0, vitest.beforeAll)(async () => {
23
- process.env.NODE_ENV = "other_test";
24
- data.app = await require_createServer.createApp(port, customConfigPath);
25
- await data.app.start();
26
- data.authFetch = skipAuthentication ? fetch : await require_authFetch.generateAuthFetch(port);
27
- });
28
- (0, vitest.afterAll)(async () => {
29
- try {
30
- await Promise.race([data.app.stop?.(), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("Shutdown timeout")), 1e4))]);
31
- } catch (err) {
32
- console.warn("⚠️ Ignoring shutdown error in CI:", err.message);
33
- }
34
- try {
35
- const testDataPath = path.default.join(__dirname$1, `./data${port}`);
36
- await fs_promises.default.rm(testDataPath, {
37
- recursive: true,
38
- force: true
39
- });
40
- } catch (err) {
41
- console.warn("⚠️ Ignoring data cleanup error in CI:", err.message);
42
- }
43
- process.env.JEST_WORKER_ID = previousJestId;
44
- process.env.NODE_ENV = previousNodeEnv;
45
- });
46
- (0, vitest.beforeEach)(async () => {
47
- data.fetchMock = vitest.vi.fn(data.authFetch);
48
- await require_resourceUtils.initResources(data.rootUri, resourceInfo, data.authFetch);
49
- });
50
- (0, vitest.afterEach)(async () => {
51
- await require_resourceUtils.cleanResources(data.rootUri, resourceInfo, data.authFetch);
52
- });
53
- return data;
54
- }
55
- //#endregion
56
- exports.setupServer = setupServer;
@@ -1,14 +0,0 @@
1
- import { ResourceInfo } from "./resourceUtils.cjs";
2
- import { App } from "@solid/community-server";
3
- import { MockedFunction } from "vitest";
4
-
5
- //#region src/setupTestServer.d.ts
6
- declare function setupServer(port: number, resourceInfo: ResourceInfo, customConfigPath?: string, skipAuthentication?: boolean): {
7
- app: App;
8
- fetchMock: MockedFunction<(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>>;
9
- authFetch: typeof fetch;
10
- rootUri: string;
11
- };
12
- //#endregion
13
- export { setupServer };
14
- //# sourceMappingURL=setupTestServer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupTestServer.d.cts","names":[],"sources":["../src/setupTestServer.ts"],"mappings":";;;;;iBA0BgB,WAAA,CACd,IAAA,UACA,YAAA,EAAc,YAAA,EACd,gBAAA,WACA,kBAAA;OAGO,GAAA;aACM,cAAA,EAEP,KAAA,EAAO,WAAA,GAAc,GAAA,EACrB,IAAA,GAAO,WAAA,iBACJ,OAAA,CAAQ,QAAA;oBAEG,KAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupTestServer.d.mts","names":[],"sources":["../src/setupTestServer.ts"],"mappings":";;;;;iBA0BgB,WAAA,CACd,IAAA,UACA,YAAA,EAAc,YAAA,EACd,gBAAA,WACA,kBAAA;OAGO,GAAA;aACM,cAAA,EAEP,KAAA,EAAO,WAAA,GAAc,GAAA,EACrB,IAAA,GAAO,WAAA,iBACJ,OAAA,CAAQ,QAAA;oBAEG,KAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupTestServer.mjs","names":[],"sources":["../src/setupTestServer.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { App } from \"@solid/community-server\";\nimport { createApp } from \"./createServer\";\nimport path from \"path\";\nimport type { ResourceInfo } from \"./resourceUtils\";\nimport { cleanResources, initResources } from \"./resourceUtils\";\nimport { generateAuthFetch } from \"./authFetch\";\nimport fs from \"fs/promises\";\nimport {\n beforeAll,\n afterAll,\n beforeEach,\n afterEach,\n vi,\n type MockedFunction,\n} from \"vitest\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\n// Use an increased timeout, since the CSS server takes too much setup time.\nvi.setConfig({ testTimeout: 40_000, hookTimeout: 40_000 });\n\nexport function setupServer(\n port: number,\n resourceInfo: ResourceInfo,\n customConfigPath?: string,\n skipAuthentication?: boolean,\n) {\n const data: {\n app: App;\n fetchMock: MockedFunction<\n (\n input: RequestInfo | URL,\n init?: RequestInit | undefined,\n ) => Promise<Response>\n >;\n authFetch: typeof fetch;\n rootUri: string;\n } = {\n rootUri: `http://localhost:${port}/`,\n } as any;\n\n let previousJestId: string | undefined;\n let previousNodeEnv: string | undefined;\n beforeAll(async () => {\n // Remove Jest ID so that community solid server doesn't use the Jest Import\n process.env.NODE_ENV = \"other_test\";\n // Start up the server\n data.app = await createApp(port, customConfigPath);\n await data.app.start();\n data.authFetch = skipAuthentication ? fetch : await generateAuthFetch(port);\n });\n\n afterAll(async () => {\n // We're potentially ignoring data clean up and server shutdown because\n // sometimes this doesn't work in CI.\n try {\n await Promise.race([\n data.app.stop?.(),\n new Promise((_, reject) =>\n setTimeout(() => reject(new Error(\"Shutdown timeout\")), 10000),\n ),\n ]);\n } catch (err) {\n console.warn(\"⚠️ Ignoring shutdown error in CI:\", (err as Error).message);\n }\n\n try {\n const testDataPath = path.join(__dirname, `./data${port}`);\n await fs.rm(testDataPath, { recursive: true, force: true });\n } catch (err) {\n console.warn(\n \"⚠️ Ignoring data cleanup error in CI:\",\n (err as Error).message,\n );\n }\n\n process.env.JEST_WORKER_ID = previousJestId;\n process.env.NODE_ENV = previousNodeEnv;\n });\n\n beforeEach(async () => {\n data.fetchMock = vi.fn(data.authFetch);\n // Create a new document called sample.ttl\n await initResources(data.rootUri, resourceInfo, data.authFetch);\n });\n\n afterEach(async () => {\n await cleanResources(data.rootUri, resourceInfo, data.authFetch);\n });\n\n return data;\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAGzD,GAAG,UAAU;CAAE,aAAa;CAAQ,aAAa;CAAQ,CAAC;AAE1D,SAAgB,YACd,MACA,cACA,kBACA,oBACA;CACA,MAAM,OAUF,EACF,SAAS,oBAAoB,KAAK,IACnC;CAED,IAAI;CACJ,IAAI;AACJ,WAAU,YAAY;AAEpB,UAAQ,IAAI,WAAW;AAEvB,OAAK,MAAM,MAAM,UAAU,MAAM,iBAAiB;AAClD,QAAM,KAAK,IAAI,OAAO;AACtB,OAAK,YAAY,qBAAqB,QAAQ,MAAM,kBAAkB,KAAK;GAC3E;AAEF,UAAS,YAAY;AAGnB,MAAI;AACF,SAAM,QAAQ,KAAK,CACjB,KAAK,IAAI,QAAQ,EACjB,IAAI,SAAS,GAAG,WACd,iBAAiB,uBAAO,IAAI,MAAM,mBAAmB,CAAC,EAAE,IAAM,CAC/D,CACF,CAAC;WACK,KAAK;AACZ,WAAQ,KAAK,qCAAsC,IAAc,QAAQ;;AAG3E,MAAI;GACF,MAAM,eAAe,KAAK,KAAK,WAAW,SAAS,OAAO;AAC1D,SAAM,GAAG,GAAG,cAAc;IAAE,WAAW;IAAM,OAAO;IAAM,CAAC;WACpD,KAAK;AACZ,WAAQ,KACN,yCACC,IAAc,QAChB;;AAGH,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI,WAAW;GACvB;AAEF,YAAW,YAAY;AACrB,OAAK,YAAY,GAAG,GAAG,KAAK,UAAU;AAEtC,QAAM,cAAc,KAAK,SAAS,cAAc,KAAK,UAAU;GAC/D;AAEF,WAAU,YAAY;AACpB,QAAM,eAAe,KAAK,SAAS,cAAc,KAAK,UAAU;GAChE;AAEF,QAAO"}