From 5126356c940bb12d9765bbd3571b6f1f6fa65cd0 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Wed, 26 Aug 2020 10:25:47 +0200 Subject: [PATCH 1/5] feat: Move runtime config into dedicated component, Closes #67 * Move runtime config into dedicated component, Closes #67 * Migrate FileResourceStore to RuntimeConfig --- bin/server.ts | 21 ++--- index.ts | 1 + src/init/RuntimeConfig.ts | 38 +++++++++ src/init/Setup.ts | 20 +++-- src/storage/FileResourceStore.ts | 21 +++-- src/storage/SimpleResourceStore.ts | 14 ++-- src/storage/UrlContainerManager.ts | 9 +- .../AuthenticatedLdpHandler.test.ts | 5 +- test/integration/Authorization.test.ts | 5 +- test/unit/init/RuntimeConfig.test.ts | 43 ++++++++++ test/unit/init/Setup.test.ts | 7 +- test/unit/storage/FileResourceStore.test.ts | 82 ++++++++++--------- test/unit/storage/SimpleResourceStore.test.ts | 3 +- test/unit/storage/UrlContainerManager.test.ts | 9 +- 14 files changed, 194 insertions(+), 84 deletions(-) create mode 100644 src/init/RuntimeConfig.ts create mode 100644 test/unit/init/RuntimeConfig.test.ts diff --git a/bin/server.ts b/bin/server.ts index acfaeaeb1f..042b71779a 100644 --- a/bin/server.ts +++ b/bin/server.ts @@ -11,6 +11,7 @@ import { QuadToTurtleConverter, Representation, RepresentationConvertingStore, + RuntimeConfig, Setup, SimpleAclAuthorizer, SimpleBodyParser, @@ -36,15 +37,13 @@ import { const { argv } = yargs .usage('node ./bin/server.js [args]') .options({ - port: { type: 'number', alias: 'p', default: 3000 }, + port: { type: 'number', alias: 'p' }, }) .help(); -const { port } = argv; - -const base = `http://localhost:${port}/`; - // This is instead of the dependency injection that still needs to be added +const runtimeConfig = new RuntimeConfig(); + const bodyParser = new CompositeAsyncHandler([ new SimpleSparqlUpdateBodyParser(), new SimpleBodyParser(), @@ -62,7 +61,7 @@ const permissionsExtractor = new CompositeAsyncHandler([ ]); // Will have to see how to best handle this -const store = new SimpleResourceStore(base); +const store = new SimpleResourceStore(runtimeConfig); const converter = new CompositeAsyncHandler([ new TurtleToQuadConverter(), new QuadToTurtleConverter(), @@ -73,7 +72,7 @@ const patcher = new SimpleSparqlUpdatePatchHandler(convertingStore, locker); const patchingStore = new PatchingStore(convertingStore, patcher); const aclManager = new SimpleExtensionAclManager(); -const containerManager = new UrlContainerManager(base); +const containerManager = new UrlContainerManager(runtimeConfig); const authorizer = new SimpleAclAuthorizer(aclManager, containerManager, patchingStore); const operationHandler = new CompositeAsyncHandler([ @@ -97,9 +96,11 @@ const httpHandler = new AuthenticatedLdpHandler({ const httpServer = new ExpressHttpServer(httpHandler); -const setup = new Setup(httpServer, store, aclManager); -setup.setup(port, base).then((): void => { - process.stdout.write(`Running at ${base}\n`); +const setup = new Setup(httpServer, store, aclManager, runtimeConfig); + +runtimeConfig.reset({ port: argv.port }); +setup.setup().then((): void => { + process.stdout.write(`Running at ${runtimeConfig.base}\n`); }).catch((error): void => { process.stderr.write(`${error}\n`); process.exit(1); diff --git a/index.ts b/index.ts index b1cdcb5f4c..5425865dd6 100644 --- a/index.ts +++ b/index.ts @@ -11,6 +11,7 @@ export * from './src/authorization/SimpleAuthorizer'; export * from './src/authorization/SimpleExtensionAclManager'; // Init +export * from './src/init/RuntimeConfig'; export * from './src/init/Setup'; // LDP/HTTP diff --git a/src/init/RuntimeConfig.ts b/src/init/RuntimeConfig.ts new file mode 100644 index 0000000000..d0d4d572cf --- /dev/null +++ b/src/init/RuntimeConfig.ts @@ -0,0 +1,38 @@ +/** + * This class holds all configuration options that can be defined by the user via the command line. + * + * Concretely, this contains data that is only relevant *after* dependency injection. + */ +export class RuntimeConfig implements RuntimeConfigData { + private pport!: number; + private pbase!: string; + private prootFilepath!: string; + + public constructor(data: RuntimeConfigData = {}) { + this.reset(data); + } + + public reset(data: RuntimeConfigData): void { + this.pport = data.port ?? 3000; + this.pbase = data.base ?? `http://localhost:${this.port}/`; + this.prootFilepath = data.rootFilepath ?? process.cwd(); + } + + public get base(): string { + return this.pbase; + } + + public get port(): number { + return this.pport; + } + + public get rootFilepath(): string { + return this.prootFilepath; + } +} + +export interface RuntimeConfigData { + port?: number; + base?: string; + rootFilepath?: string; +} diff --git a/src/init/Setup.ts b/src/init/Setup.ts index 9aa3d9a18c..8a45bbfb0c 100644 --- a/src/init/Setup.ts +++ b/src/init/Setup.ts @@ -2,6 +2,7 @@ import { AclManager } from '../authorization/AclManager'; import { DATA_TYPE_BINARY } from '../util/ContentTypes'; import { ExpressHttpServer } from '../server/ExpressHttpServer'; import { ResourceStore } from '../storage/ResourceStore'; +import { RuntimeConfig } from './RuntimeConfig'; import streamifyArray from 'streamify-array'; /** @@ -11,11 +12,18 @@ export class Setup { private readonly httpServer: ExpressHttpServer; private readonly store: ResourceStore; private readonly aclManager: AclManager; + private readonly runtimeConfig: RuntimeConfig; - public constructor(httpServer: ExpressHttpServer, store: ResourceStore, aclManager: AclManager) { + public constructor( + httpServer: ExpressHttpServer, + store: ResourceStore, + aclManager: AclManager, + runtimeConfig: RuntimeConfig, + ) { this.httpServer = httpServer; this.store = store; this.aclManager = aclManager; + this.runtimeConfig = runtimeConfig; } /** @@ -23,7 +31,7 @@ export class Setup { * @param port - A port number. * @param base - A base URL. */ - public async setup(port: number, base: string): Promise { + public async setup(): Promise { // Set up acl so everything can still be done by default // Note that this will need to be adapted to go through all the correct channels later on const aclSetup = async(): Promise => { @@ -38,10 +46,10 @@ export class Setup { acl:mode acl:Append; acl:mode acl:Delete; acl:mode acl:Control; - acl:accessTo <${base}>; - acl:default <${base}>.`; + acl:accessTo <${this.runtimeConfig.base}>; + acl:default <${this.runtimeConfig.base}>.`; await this.store.setRepresentation( - await this.aclManager.getAcl({ path: base }), + await this.aclManager.getAcl({ path: this.runtimeConfig.base }), { dataType: DATA_TYPE_BINARY, data: streamifyArray([ acl ]), @@ -56,6 +64,6 @@ export class Setup { await aclSetup(); - this.httpServer.listen(port); + this.httpServer.listen(this.runtimeConfig.port); } } diff --git a/src/storage/FileResourceStore.ts b/src/storage/FileResourceStore.ts index 4df3b8543d..d04cef932a 100644 --- a/src/storage/FileResourceStore.ts +++ b/src/storage/FileResourceStore.ts @@ -12,6 +12,7 @@ import { Representation } from '../ldp/representation/Representation'; import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { ResourceStore } from './ResourceStore'; +import { RuntimeConfig } from '../init/RuntimeConfig'; import streamifyArray from 'streamify-array'; import { UnsupportedMediaTypeHttpError } from '../util/errors/UnsupportedMediaTypeHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../util/ContentTypes'; @@ -25,26 +26,30 @@ const { extname, join: joinPath, normalize: normalizePath } = posix; * All requests will throw an {@link NotFoundHttpError} if unknown identifiers get passed. */ export class FileResourceStore implements ResourceStore { - private readonly baseRequestURI: string; - private readonly rootFilepath: string; + private readonly runtimeConfig: RuntimeConfig; private readonly interactionController: InteractionController; private readonly metadataController: MetadataController; /** - * @param baseRequestURI - Will be stripped of all incoming URIs and added to all outgoing ones to find the relative - * path. - * @param rootFilepath - Root filepath in which the resources and containers will be saved as files and directories. + * @param runtimeConfig - The runtime config. * @param interactionController - Instance of InteractionController to use. * @param metadataController - Instance of MetadataController to use. */ - public constructor(baseRequestURI: string, rootFilepath: string, interactionController: InteractionController, + public constructor(runtimeConfig: RuntimeConfig, interactionController: InteractionController, metadataController: MetadataController) { - this.baseRequestURI = trimTrailingSlashes(baseRequestURI); - this.rootFilepath = trimTrailingSlashes(rootFilepath); + this.runtimeConfig = runtimeConfig; this.interactionController = interactionController; this.metadataController = metadataController; } + public get baseRequestURI(): string { + return trimTrailingSlashes(this.runtimeConfig.base); + } + + public get rootFilepath(): string { + return trimTrailingSlashes(this.runtimeConfig.rootFilepath); + } + /** * Store the incoming data as a file under a file path corresponding to `container.path`, * where slashes correspond to subdirectories. diff --git a/src/storage/SimpleResourceStore.ts b/src/storage/SimpleResourceStore.ts index b7fa1d0e45..2fae99a55e 100644 --- a/src/storage/SimpleResourceStore.ts +++ b/src/storage/SimpleResourceStore.ts @@ -5,6 +5,7 @@ import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { Representation } from '../ldp/representation/Representation'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { ResourceStore } from './ResourceStore'; +import { RuntimeConfig } from '../init/RuntimeConfig'; import streamifyArray from 'streamify-array'; /** @@ -13,14 +14,15 @@ import streamifyArray from 'streamify-array'; */ export class SimpleResourceStore implements ResourceStore { private readonly store: { [id: string]: Representation }; - private readonly base: string; + private readonly runtimeConfig: RuntimeConfig; private index = 0; /** - * @param base - Will be stripped of all incoming URIs and added to all outgoing ones to find the relative path. + * @param runtimeConfig - Config containing base that will be stripped of all incoming URIs + * and added to all outgoing ones to find the relative path. */ - public constructor(base: string) { - this.base = base; + public constructor(runtimeConfig: RuntimeConfig) { + this.runtimeConfig = runtimeConfig; this.store = { // Default root entry (what you get when the identifier is equal to the base) @@ -102,8 +104,8 @@ export class SimpleResourceStore implements ResourceStore { * @returns A string representing the relative path. */ private parseIdentifier(identifier: ResourceIdentifier): string { - const path = identifier.path.slice(this.base.length); - if (!identifier.path.startsWith(this.base)) { + const path = identifier.path.slice(this.runtimeConfig.base.length); + if (!identifier.path.startsWith(this.runtimeConfig.base)) { throw new NotFoundHttpError(); } return path; diff --git a/src/storage/UrlContainerManager.ts b/src/storage/UrlContainerManager.ts index e6ce845ea2..07a1435f12 100644 --- a/src/storage/UrlContainerManager.ts +++ b/src/storage/UrlContainerManager.ts @@ -1,20 +1,21 @@ import { ContainerManager } from './ContainerManager'; import { ensureTrailingSlash } from '../util/Util'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { RuntimeConfig } from '../init/RuntimeConfig'; /** * Determines containers based on URL decomposition. */ export class UrlContainerManager implements ContainerManager { - private readonly root: string; + private readonly runtimeConfig: RuntimeConfig; - public constructor(root: string) { - this.root = this.canonicalUrl(root); + public constructor(runtimeConfig: RuntimeConfig) { + this.runtimeConfig = runtimeConfig; } public async getContainer(id: ResourceIdentifier): Promise { const path = this.canonicalUrl(id.path); - if (this.root === path) { + if (this.canonicalUrl(this.runtimeConfig.base) === path) { throw new Error('Root does not have a container.'); } diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index d5434ad9ed..41238e1fc6 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -13,6 +13,7 @@ import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtle import { Representation } from '../../src/ldp/representation/Representation'; import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription'; +import { RuntimeConfig } from '../../src/init/RuntimeConfig'; import { SimpleAuthorizer } from '../../src/authorization/SimpleAuthorizer'; import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; @@ -44,7 +45,7 @@ describe('An integrated AuthenticatedLdpHandler', (): void => { const permissionsExtractor = new BasePermissionsExtractor(); const authorizer = new SimpleAuthorizer(); - const store = new SimpleResourceStore('http://test.com/'); + const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' })); const operationHandler = new CompositeAsyncHandler([ new SimpleGetOperationHandler(store), new SimplePostOperationHandler(store), @@ -115,7 +116,7 @@ describe('An integrated AuthenticatedLdpHandler', (): void => { ]); const authorizer = new SimpleAuthorizer(); - const store = new SimpleResourceStore('http://test.com/'); + const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' })); const converter = new CompositeAsyncHandler([ new QuadToTurtleConverter(), new TurtleToQuadConverter(), diff --git a/test/integration/Authorization.test.ts b/test/integration/Authorization.test.ts index d47df48a52..aa3dd809b2 100644 --- a/test/integration/Authorization.test.ts +++ b/test/integration/Authorization.test.ts @@ -12,6 +12,7 @@ import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtle import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; import { ResourceStore } from '../../src/storage/ResourceStore'; import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription'; +import { RuntimeConfig } from '../../src/init/RuntimeConfig'; import { SimpleAclAuthorizer } from '../../src/authorization/SimpleAclAuthorizer'; import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; @@ -80,7 +81,7 @@ describe('A server with authorization', (): void => { bodyParser, }); - const store = new SimpleResourceStore('http://test.com/'); + const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' })); const converter = new CompositeAsyncHandler([ new QuadToTurtleConverter(), new TurtleToQuadConverter(), @@ -91,7 +92,7 @@ describe('A server with authorization', (): void => { const permissionsExtractor = new BasePermissionsExtractor(); const authorizer = new SimpleAclAuthorizer( new SimpleExtensionAclManager(), - new UrlContainerManager('http://test.com/'), + new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/' })), convertingStore, ); diff --git a/test/unit/init/RuntimeConfig.test.ts b/test/unit/init/RuntimeConfig.test.ts new file mode 100644 index 0000000000..36a6096746 --- /dev/null +++ b/test/unit/init/RuntimeConfig.test.ts @@ -0,0 +1,43 @@ +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; + +describe('RuntimeConfig', (): void => { + it('handles undefined args.', async(): Promise => { + const config = new RuntimeConfig(); + expect(config.port).toEqual(3000); + expect(config.base).toEqual('http://localhost:3000/'); + }); + + it('handles empty args.', async(): Promise => { + const config = new RuntimeConfig({}); + expect(config.port).toEqual(3000); + expect(config.base).toEqual('http://localhost:3000/'); + }); + + it('handles args with port.', async(): Promise => { + const config = new RuntimeConfig({ port: 1234 }); + expect(config.port).toEqual(1234); + expect(config.base).toEqual('http://localhost:1234/'); + }); + + it('handles args with base.', async(): Promise => { + const config = new RuntimeConfig({ base: 'http://example.org/' }); + expect(config.port).toEqual(3000); + expect(config.base).toEqual('http://example.org/'); + }); + + it('handles args with port and base.', async(): Promise => { + const config = new RuntimeConfig({ port: 1234, base: 'http://example.org/' }); + expect(config.port).toEqual(1234); + expect(config.base).toEqual('http://example.org/'); + }); + + it('handles resetting data.', async(): Promise => { + const config = new RuntimeConfig({}); + expect(config.port).toEqual(3000); + expect(config.base).toEqual('http://localhost:3000/'); + + config.reset({ port: 1234, base: 'http://example.org/' }); + expect(config.port).toEqual(1234); + expect(config.base).toEqual('http://example.org/'); + }); +}); diff --git a/test/unit/init/Setup.test.ts b/test/unit/init/Setup.test.ts index 230c70901b..1a9311c8e2 100644 --- a/test/unit/init/Setup.test.ts +++ b/test/unit/init/Setup.test.ts @@ -1,3 +1,4 @@ +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import { Setup } from '../../../src/init/Setup'; describe('Setup', (): void => { @@ -15,16 +16,16 @@ describe('Setup', (): void => { httpServer = { listen: jest.fn(), }; - setup = new Setup(httpServer, store, aclManager); + setup = new Setup(httpServer, store, aclManager, new RuntimeConfig()); }); it('starts an HTTP server.', async(): Promise => { - await setup.setup(3000, 'http://localhost:3000/'); + await setup.setup(); expect(httpServer.listen).toHaveBeenCalledWith(3000); }); it('invokes ACL initialization.', async(): Promise => { - await setup.setup(3000, 'http://localhost:3000/'); + await setup.setup(); expect(aclManager.getAcl).toHaveBeenCalledWith({ path: 'http://localhost:3000/' }); expect(store.setRepresentation).toHaveBeenCalledTimes(1); }); diff --git a/test/unit/storage/FileResourceStore.test.ts b/test/unit/storage/FileResourceStore.test.ts index d88128cbe5..db1b380ed9 100644 --- a/test/unit/storage/FileResourceStore.test.ts +++ b/test/unit/storage/FileResourceStore.test.ts @@ -10,6 +10,7 @@ import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; import { posix } from 'path'; import { Readable } from 'stream'; import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import streamifyArray from 'streamify-array'; import { UnsupportedMediaTypeHttpError } from '../../../src/util/errors/UnsupportedMediaTypeHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../src/util/ContentTypes'; @@ -21,7 +22,7 @@ import { literal, namedNode, quad as quadRDF, triple } from '@rdfjs/data-model'; const { join: joinPath } = posix; const base = 'http://test.com/'; -const root = '/Users/default/home/public/'; +const rootFilepath = '/Users/default/home/public/'; fsPromises.rmdir = jest.fn(); fsPromises.lstat = jest.fn(); @@ -48,7 +49,11 @@ describe('A FileResourceStore', (): void => { beforeEach(async(): Promise => { jest.clearAllMocks(); - store = new FileResourceStore(base, root, new InteractionController(), new MetadataController()); + store = new FileResourceStore( + new RuntimeConfig({ base, rootFilepath }), + new InteractionController(), + new MetadataController(), + ); representation = { data: streamifyArray([ rawData ]), @@ -131,7 +136,7 @@ describe('A FileResourceStore', (): void => { // Write container (POST) representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, slug: 'myContainer/', raw: []}; const identifier = await store.addResource({ path: base }, representation); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(root, 'myContainer/'), { recursive: true }); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'myContainer/'), { recursive: true }); expect(identifier.path).toBe(`${base}myContainer/`); // Read container @@ -155,7 +160,7 @@ describe('A FileResourceStore', (): void => { // Tests representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, slug: 'myContainer/', raw: []}; await expect(store.addResource({ path: `${base}foo` }, representation)).rejects.toThrow(MethodNotAllowedHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo')); }); it('errors 405 for POST invalid path ending without slash.', async(): Promise => { @@ -172,17 +177,17 @@ describe('A FileResourceStore', (): void => { representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, slug: 'myContainer/', raw: []}; await expect(store.addResource({ path: `${base}doesnotexist` }, representation)) .rejects.toThrow(MethodNotAllowedHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'doesnotexist')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'doesnotexist')); representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, slug: 'file.txt', raw: []}; await expect(store.addResource({ path: `${base}doesnotexist` }, representation)) .rejects.toThrow(MethodNotAllowedHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'doesnotexist')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'doesnotexist')); representation.metadata = { linkRel: { type: new Set() }, slug: 'file.txt', raw: []}; await expect(store.addResource({ path: `${base}existingresource` }, representation)) .rejects.toThrow(MethodNotAllowedHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'existingresource')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'existingresource')); }); it('can set data.', async(): Promise => { @@ -204,7 +209,7 @@ describe('A FileResourceStore', (): void => { // Tests await store.setRepresentation({ path: `${base}file.txt` }, representation); - expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); + expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); const result = await store.getRepresentation({ path: `${base}file.txt` }); expect(result).toEqual({ dataType: DATA_TYPE_BINARY, @@ -217,9 +222,9 @@ describe('A FileResourceStore', (): void => { }, }); await expect(arrayifyStream(result.data)).resolves.toEqual([ rawData ]); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); - expect(fs.createReadStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); - expect(fs.createReadStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt.metadata')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); + expect(fs.createReadStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); + expect(fs.createReadStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt.metadata')); }); it('can delete data.', async(): Promise => { @@ -239,7 +244,7 @@ describe('A FileResourceStore', (): void => { // Tests await store.deleteResource({ path: `${base}file.txt` }); - expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); + expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); await expect(store.getRepresentation({ path: `${base}file.txt` })).rejects.toThrow(NotFoundHttpError); }); @@ -253,8 +258,9 @@ describe('A FileResourceStore', (): void => { representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, slug: 'file.txt', raw: []}; const identifier = await store.addResource({ path: `${base}doesnotexistyet/` }, representation); expect(identifier.path).toBe(`${base}doesnotexistyet/file.txt`); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(root, 'doesnotexistyet/'), { recursive: true }); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'doesnotexistyet/')); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'doesnotexistyet/'), + { recursive: true }); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'doesnotexistyet/')); }); it('creates metadata file when metadata triples are passed.', async(): Promise => { @@ -277,8 +283,8 @@ describe('A FileResourceStore', (): void => { representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, raw: [ quad ]}; representation.data = readableMock; await store.addResource({ path: `${base}foo/` }, representation); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo/'), { recursive: true }); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/'), { recursive: true }); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, raw: [ quad ]}; await store.setRepresentation({ path: `${base}foo/file.txt` }, representation); @@ -298,8 +304,8 @@ describe('A FileResourceStore', (): void => { // Tests await expect(store.deleteResource({ path: `${base}notempty/` })).rejects.toThrow(ConflictHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'notempty/')); - expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(root, 'notempty/')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'notempty/')); + expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'notempty/')); }); it('deletes metadata file when deleting container.', async(): Promise => { @@ -312,10 +318,10 @@ describe('A FileResourceStore', (): void => { // Tests await store.deleteResource({ path: `${base}foo/` }); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); - expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); - expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(root, 'foo', '.metadata')); - expect(fsPromises.rmdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); + expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); + expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo', '.metadata')); + expect(fsPromises.rmdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); }); it('errors 404 when accessing non resource (file/directory), e.g. special files.', async(): Promise => { @@ -368,10 +374,10 @@ describe('A FileResourceStore', (): void => { }, }); await expect(arrayifyStream(result.data)).resolves.toEqualRdfQuadArray(quads); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); - expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo', 'file.txt')); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo', '.nonresource')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); + expect(fsPromises.readdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo', 'file.txt')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo', '.nonresource')); }); it('can overwrite representation with PUT.', async(): Promise => { @@ -387,8 +393,8 @@ describe('A FileResourceStore', (): void => { representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, raw: []}; await store.setRepresentation({ path: `${base}alreadyexists.txt` }, representation); expect(fs.createWriteStream as jest.Mock).toBeCalledTimes(1); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'alreadyexists.txt')); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(root, { recursive: true }); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'alreadyexists.txt')); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(rootFilepath, { recursive: true }); }); it('errors when overwriting container with PUT.', async(): Promise => { @@ -399,7 +405,7 @@ describe('A FileResourceStore', (): void => { // Tests await expect(store.setRepresentation({ path: `${base}alreadyexists` }, representation)).rejects .toThrow(ConflictHttpError); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'alreadyexists')); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'alreadyexists')); representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, raw: []}; await expect(store.setRepresentation({ path: `${base}alreadyexists/` }, representation)).rejects .toThrow(ConflictHttpError); @@ -445,9 +451,9 @@ describe('A FileResourceStore', (): void => { // Tests representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDPR ]) }, slug: 'file.txt', raw: [ quad ]}; await expect(store.addResource({ path: base }, representation)).rejects.toThrow(Error); - expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt.metadata')); - expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); - expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt.metadata')); + expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt.metadata')); + expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); + expect(fsPromises.unlink as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt.metadata')); }); it('undoes container creation when metadata file creation fails.', async(): Promise => { @@ -461,7 +467,7 @@ describe('A FileResourceStore', (): void => { // Tests representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, slug: 'foo/', raw: [ quad ]}; await expect(store.addResource({ path: base }, representation)).rejects.toThrow(Error); - expect(fsPromises.rmdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo/')); + expect(fsPromises.rmdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo/')); }); it('creates container when POSTing without linkRel and with slug ending with slash.', async(): Promise => { @@ -474,7 +480,7 @@ describe('A FileResourceStore', (): void => { const identifier = await store.addResource({ path: base }, representation); expect(identifier.path).toBe(`${base}myContainer/`); expect(fsPromises.mkdir as jest.Mock).toBeCalledTimes(1); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(root, 'myContainer/'), { recursive: true }); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'myContainer/'), { recursive: true }); }); it('returns no contentType when unknown for representation.', async(): Promise => { @@ -514,9 +520,9 @@ describe('A FileResourceStore', (): void => { // Tests representation.metadata = { raw: []}; await store.setRepresentation({ path: `${base}file.txt` }, representation); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(root, { recursive: true }); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(rootFilepath, { recursive: true }); expect(fs.createWriteStream as jest.Mock).toBeCalledTimes(1); - expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(root, 'file.txt')); + expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt')); }); it('creates container when POST to existing container path ending without slash and slug without slash.', @@ -530,7 +536,7 @@ describe('A FileResourceStore', (): void => { representation.metadata = { linkRel: { type: new Set([ LINK_TYPE_LDP_BC ]) }, slug: 'bar', raw: []}; const identifier = await store.addResource({ path: `${base}foo` }, representation); expect(identifier.path).toBe(`${base}foo/bar/`); - expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(root, 'foo')); - expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(root, 'foo', 'bar/'), { recursive: false }); + expect(fsPromises.lstat as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo')); + expect(fsPromises.mkdir as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'foo', 'bar/'), { recursive: false }); }); }); diff --git a/test/unit/storage/SimpleResourceStore.test.ts b/test/unit/storage/SimpleResourceStore.test.ts index c63040c427..546337d7b7 100644 --- a/test/unit/storage/SimpleResourceStore.test.ts +++ b/test/unit/storage/SimpleResourceStore.test.ts @@ -4,6 +4,7 @@ import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes'; import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; import { Readable } from 'stream'; import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import { SimpleResourceStore } from '../../../src/storage/SimpleResourceStore'; import streamifyArray from 'streamify-array'; @@ -15,7 +16,7 @@ describe('A SimpleResourceStore', (): void => { const dataString = ' .'; beforeEach(async(): Promise => { - store = new SimpleResourceStore(base); + store = new SimpleResourceStore(new RuntimeConfig({ base })); representation = { data: streamifyArray([ dataString ]), diff --git a/test/unit/storage/UrlContainerManager.test.ts b/test/unit/storage/UrlContainerManager.test.ts index a6c7860719..4df65bf8f5 100644 --- a/test/unit/storage/UrlContainerManager.test.ts +++ b/test/unit/storage/UrlContainerManager.test.ts @@ -1,8 +1,9 @@ +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import { UrlContainerManager } from '../../../src/storage/UrlContainerManager'; describe('An UrlContainerManager', (): void => { it('returns the parent URl for a single call.', async(): Promise => { - const manager = new UrlContainerManager('http://test.com/foo/'); + const manager = new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/foo/' })); await expect(manager.getContainer({ path: 'http://test.com/foo/bar' })) .resolves.toEqual({ path: 'http://test.com/foo/' }); await expect(manager.getContainer({ path: 'http://test.com/foo/bar/' })) @@ -10,13 +11,13 @@ describe('An UrlContainerManager', (): void => { }); it('errors when getting the container of root.', async(): Promise => { - let manager = new UrlContainerManager('http://test.com/foo/'); + let manager = new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/foo/' })); await expect(manager.getContainer({ path: 'http://test.com/foo/' })) .rejects.toThrow('Root does not have a container.'); await expect(manager.getContainer({ path: 'http://test.com/foo' })) .rejects.toThrow('Root does not have a container.'); - manager = new UrlContainerManager('http://test.com/foo'); + manager = new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/foo' })); await expect(manager.getContainer({ path: 'http://test.com/foo/' })) .rejects.toThrow('Root does not have a container.'); await expect(manager.getContainer({ path: 'http://test.com/foo' })) @@ -24,7 +25,7 @@ describe('An UrlContainerManager', (): void => { }); it('errors when the root of an URl is reached that does not match the input root.', async(): Promise => { - const manager = new UrlContainerManager('http://test.com/foo/'); + const manager = new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/foo/' })); await expect(manager.getContainer({ path: 'http://test.com/' })) .rejects.toThrow('URL root reached.'); }); From 48740e5cbad95b03868f8eb989520050ce0eff4b Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Wed, 26 Aug 2020 10:35:51 +0200 Subject: [PATCH 2/5] style: improve linting of imports A new plugin is used that offers autofixing capabilities. --- .eslintrc.js | 22 + package-lock.json | 510 ++++++++++++++++++ package.json | 3 + src/authentication/CredentialsExtractor.ts | 2 +- .../SimpleCredentialsExtractor.ts | 2 +- src/authorization/Authorizer.ts | 2 +- src/authorization/SimpleAclAuthorizer.ts | 12 +- .../SimpleExtensionAclManager.ts | 2 +- src/init/Setup.ts | 4 +- src/ldp/AuthenticatedLdpHandler.ts | 8 +- src/ldp/http/AcceptPreferenceParser.ts | 6 +- src/ldp/http/BodyParser.ts | 2 +- src/ldp/http/PreferenceParser.ts | 2 +- src/ldp/http/RequestParser.ts | 2 +- src/ldp/http/ResponseWriter.ts | 2 +- src/ldp/http/SimpleBodyParser.ts | 6 +- src/ldp/http/SimpleRequestParser.ts | 2 +- src/ldp/http/SimpleResponseWriter.ts | 4 +- src/ldp/http/SimpleSparqlUpdateBodyParser.ts | 10 +- src/ldp/http/SimpleTargetExtractor.ts | 2 +- src/ldp/http/TargetExtractor.ts | 2 +- .../SimpleDeleteOperationHandler.ts | 4 +- .../operations/SimpleGetOperationHandler.ts | 4 +- .../operations/SimplePatchOperationHandler.ts | 6 +- .../operations/SimplePostOperationHandler.ts | 4 +- .../operations/SimplePutOperationHandler.ts | 4 +- .../permissions/BasePermissionsExtractor.ts | 2 +- .../SparqlPatchPermissionsExtractor.ts | 6 +- src/server/ExpressHttpServer.ts | 2 +- src/storage/FileResourceStore.ts | 24 +- src/storage/LockingResourceStore.ts | 6 +- src/storage/PassthroughStore.ts | 2 +- src/storage/PatchingStore.ts | 4 +- src/storage/RepresentationConvertingStore.ts | 8 +- src/storage/ResourceLocker.ts | 2 +- src/storage/ResourceStore.ts | 2 +- src/storage/SimpleResourceStore.ts | 10 +- src/storage/SingleThreadedResourceLocker.ts | 2 +- src/storage/UrlContainerManager.ts | 6 +- src/storage/conversion/ConversionUtil.ts | 4 +- .../conversion/QuadToTurtleConverter.ts | 4 +- .../conversion/RepresentationConverter.ts | 2 +- .../conversion/TurtleToQuadConverter.ts | 6 +- src/storage/patch/PatchHandler.ts | 2 +- .../patch/SimpleSparqlUpdatePatchHandler.ts | 18 +- src/util/InteractionController.ts | 2 +- src/util/MetadataController.ts | 8 +- src/util/Util.ts | 2 +- .../AuthenticatedLdpHandler.test.ts | 48 +- test/integration/Authorization.test.ts | 40 +- test/integration/RequestParser.test.ts | 10 +- .../SimpleCredentialsExtractor.test.ts | 2 +- .../authorization/SimpleAclAuthorizer.test.ts | 14 +- test/unit/ldp/AuthenticatedLdpHandler.test.ts | 12 +- test/unit/ldp/http/SimpleBodyParser.test.ts | 8 +- .../unit/ldp/http/SimpleRequestParser.test.ts | 2 +- .../ldp/http/SimpleResponseWriter.test.ts | 8 +- .../http/SimpleSparqlUpdateBodyParser.test.ts | 10 +- .../SimpleDeleteOperationHandler.test.ts | 2 +- .../SimpleGetOperationHandler.test.ts | 4 +- .../SimplePatchOperationHandler.test.ts | 2 +- .../SimplePostOperationHandler.test.ts | 2 +- .../SimplePutOperationHandler.test.ts | 2 +- .../BasePermissionsExtractor.test.ts | 2 +- .../SparqlPatchPermissionsExtractor.test.ts | 2 +- test/unit/server/ExpressHttpServer.test.ts | 4 +- test/unit/storage/FileResourceStore.test.ts | 26 +- .../unit/storage/LockingResourceStore.test.ts | 6 +- test/unit/storage/PassthroughStore.test.ts | 2 +- test/unit/storage/SimpleResourceStore.test.ts | 10 +- .../conversion/QuadToTurtleConverter.test.ts | 8 +- .../conversion/TurtleToQuadConverter.test.ts | 8 +- .../SimpleSparqlUpdatePatchHandler.test.ts | 14 +- test/util/Util.ts | 6 +- 74 files changed, 771 insertions(+), 236 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 32a804f2ca..88cfe03c20 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,10 +7,22 @@ module.exports = { }, plugins: [ 'eslint-plugin-tsdoc', + 'eslint-plugin-import', + 'eslint-plugin-unused-imports' ], extends: [ 'es/node', + 'plugin:import/errors', + 'plugin:import/warnings', + 'plugin:import/typescript' ], + settings: { + 'import/resolver': { + 'typescript': { + 'alwaysTryTypes': true // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/rdf-js` + }, + } + }, rules: { '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', // problems with optional parameters @@ -24,5 +36,15 @@ module.exports = { 'padding-line-between-statements': 'off', 'tsdoc/syntax': 'error', 'prefer-named-capture-group': 'off', + + // Import + 'sort-imports': 'off', // Disabled in favor of eslint-plugin-import + 'import/order': ['error', { + alphabetize: { + order: 'asc', + caseInsensitive: true + } + }], + 'unused-imports/no-unused-imports-ts': 'error', }, }; diff --git a/package-lock.json b/package-lock.json index 167e50723d..f028419298 100644 --- a/package-lock.json +++ b/package-lock.json @@ -942,6 +942,12 @@ "integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==", "dev": true }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", + "dev": true + }, "@types/mime": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.2.tgz", @@ -1322,6 +1328,16 @@ "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", "dev": true }, + "array.prototype.flat": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.3.tgz", + "integrity": "sha512-gBlRZV0VSmfPIeWfuuy56XZMvbVfbEUnOXUvt3F/eUUUSyzlgLxhEX4YAEpxNAogRGehPSnfXyPtYyKAhkzQhQ==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + } + }, "arrayify-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/arrayify-stream/-/arrayify-stream-1.0.0.tgz", @@ -1931,6 +1947,12 @@ "xdg-basedir": "^4.0.0" } }, + "contains-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", + "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", + "dev": true + }, "content-disposition": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", @@ -2626,6 +2648,131 @@ } } }, + "eslint-import-resolver-node": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz", + "integrity": "sha512-ogtf+5AB/O+nM6DIeBUNr2fuT7ot9Qg/1harBfBtaP13ekEWFQEEMP94BCB7zaNW3gyY+8SHYF00rnqYwXKWOA==", + "dev": true, + "requires": { + "debug": "^2.6.9", + "resolve": "^1.13.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + } + } + }, + "eslint-import-resolver-typescript": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.2.1.tgz", + "integrity": "sha512-wxlVdwuWY6R5+CoesIy6n8EZX4k9lEeZGWTVBoX9g//8Xma8JMtL/p3AGnG43rRyXmIrX+/0IN8lpOPzrw1fSw==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "resolve": "^1.17.0", + "tsconfig-paths": "^3.9.0" + } + }, + "eslint-module-utils": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz", + "integrity": "sha512-6j9xxegbqe8/kZY8cYpcp0xhbK0EgJlg3g9mib3/miLaExuuwc3n5UEfSnU6hWMbT0FAYVvDbL9RrRgpUeQIvA==", + "dev": true, + "requires": { + "debug": "^2.6.9", + "pkg-dir": "^2.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "pkg-dir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-2.0.0.tgz", + "integrity": "sha1-9tXREJ4Z1j7fQo4L1X4Sd3YVM0s=", + "dev": true, + "requires": { + "find-up": "^2.1.0" + } + } + } + }, "eslint-plugin-extended": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eslint-plugin-extended/-/eslint-plugin-extended-0.2.0.tgz", @@ -2635,6 +2782,133 @@ "varname": "2.0.2" } }, + "eslint-plugin-import": { + "version": "2.22.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.22.0.tgz", + "integrity": "sha512-66Fpf1Ln6aIS5Gr/55ts19eUuoDhAbZgnr6UxK5hbDx6l/QgQgx61AePq+BV4PP2uXQFClgMVzep5zZ94qqsxg==", + "dev": true, + "requires": { + "array-includes": "^3.1.1", + "array.prototype.flat": "^1.2.3", + "contains-path": "^0.1.0", + "debug": "^2.6.9", + "doctrine": "1.5.0", + "eslint-import-resolver-node": "^0.3.3", + "eslint-module-utils": "^2.6.0", + "has": "^1.0.3", + "minimatch": "^3.0.4", + "object.values": "^1.1.1", + "read-pkg-up": "^2.0.0", + "resolve": "^1.17.0", + "tsconfig-paths": "^3.9.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "isarray": "^1.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, + "path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", + "dev": true, + "requires": { + "pify": "^2.0.0" + } + }, + "read-pkg": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", + "dev": true, + "requires": { + "load-json-file": "^2.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^2.0.0" + } + }, + "read-pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", + "dev": true, + "requires": { + "find-up": "^2.0.0", + "read-pkg": "^2.0.0" + } + } + } + }, "eslint-plugin-mocha": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-6.3.0.tgz", @@ -2721,6 +2995,172 @@ } } }, + "eslint-plugin-unused-imports": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-0.1.3.tgz", + "integrity": "sha512-hNbmvUhfy+Nf+9t2Sx720FsFRMkpWLaN5QSw0yUyplcOugvnRaLg9ylAK6DFu/S3J+IiPiHueZHKJh7lhggAXA==", + "dev": true, + "requires": { + "@typescript-eslint/eslint-plugin": "^2.3.0", + "eslint": "^6.3.0", + "eslint-rule-composer": "^0.3.0", + "requireindex": "~1.1.0", + "typescript": "^3.6.3" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "eslint": { + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.8.0.tgz", + "integrity": "sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.10.0", + "chalk": "^2.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^1.4.3", + "eslint-visitor-keys": "^1.1.0", + "espree": "^6.1.2", + "esquery": "^1.0.1", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^7.0.0", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.14", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.3", + "progress": "^2.0.0", + "regexpp": "^2.0.1", + "semver": "^6.1.2", + "strip-ansi": "^5.2.0", + "strip-json-comments": "^3.0.1", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + } + }, + "eslint-utils": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.3.tgz", + "integrity": "sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "espree": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.2.1.tgz", + "integrity": "sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==", + "dev": true, + "requires": { + "acorn": "^7.1.1", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.1.0" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "regexpp": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", + "dev": true + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true + }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", @@ -4721,6 +5161,35 @@ "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", "dev": true }, + "load-json-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "dev": true, + "requires": { + "error-ex": "^1.2.0" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + } + } + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -5464,6 +5933,12 @@ "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, "pirates": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.1.tgz", @@ -5922,6 +6397,12 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, + "requireindex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", + "integrity": "sha1-5UBLgVV+91225JxacgBIk/4D4WI=", + "dev": true + }, "reserved-words": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/reserved-words/-/reserved-words-0.1.2.tgz", @@ -7124,6 +7605,35 @@ } } }, + "tsconfig-paths": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", + "integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "json5": "^1.0.1", + "minimist": "^1.2.0", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + } + } + }, "tslib": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.12.0.tgz", diff --git a/package.json b/package.json index ba6e02d867..a03f235ae0 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,9 @@ "eslint": "^7.0.0", "eslint-config-es": "^3.19.61", "eslint-plugin-tsdoc": "^0.2.4", + "eslint-import-resolver-typescript": "^2.2.1", + "eslint-plugin-import": "^2.22.0", + "eslint-plugin-unused-imports": "^0.1.3", "husky": "^4.2.5", "jest": "^26.0.1", "jest-rdf": "^1.5.0", diff --git a/src/authentication/CredentialsExtractor.ts b/src/authentication/CredentialsExtractor.ts index 28c1ef271a..08d4d7c2f5 100644 --- a/src/authentication/CredentialsExtractor.ts +++ b/src/authentication/CredentialsExtractor.ts @@ -1,6 +1,6 @@ +import { HttpRequest } from '../server/HttpRequest'; import { AsyncHandler } from '../util/AsyncHandler'; import { Credentials } from './Credentials'; -import { HttpRequest } from '../server/HttpRequest'; /** * Responsible for extracting credentials from an incoming request. diff --git a/src/authentication/SimpleCredentialsExtractor.ts b/src/authentication/SimpleCredentialsExtractor.ts index 1909e60f79..757ccca5f7 100644 --- a/src/authentication/SimpleCredentialsExtractor.ts +++ b/src/authentication/SimpleCredentialsExtractor.ts @@ -1,6 +1,6 @@ +import { HttpRequest } from '../server/HttpRequest'; import { Credentials } from './Credentials'; import { CredentialsExtractor } from './CredentialsExtractor'; -import { HttpRequest } from '../server/HttpRequest'; /** * Credentials extractor which simply interprets the contents of the Authorization header as a webID. diff --git a/src/authorization/Authorizer.ts b/src/authorization/Authorizer.ts index c70c6f3849..7e24dd43da 100644 --- a/src/authorization/Authorizer.ts +++ b/src/authorization/Authorizer.ts @@ -1,7 +1,7 @@ -import { AsyncHandler } from '../util/AsyncHandler'; import { Credentials } from '../authentication/Credentials'; import { PermissionSet } from '../ldp/permissions/PermissionSet'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { AsyncHandler } from '../util/AsyncHandler'; /** * Verifies if the given credentials have access to the given permissions on the given resource. diff --git a/src/authorization/SimpleAclAuthorizer.ts b/src/authorization/SimpleAclAuthorizer.ts index 796530b763..d97a5c0da7 100644 --- a/src/authorization/SimpleAclAuthorizer.ts +++ b/src/authorization/SimpleAclAuthorizer.ts @@ -1,17 +1,17 @@ -import { AclManager } from './AclManager'; -import { ContainerManager } from '../storage/ContainerManager'; -import { CONTENT_TYPE_QUADS } from '../util/ContentTypes'; +import { Quad, Store, Term } from 'n3'; import { Credentials } from '../authentication/Credentials'; -import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError'; -import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { PermissionSet } from '../ldp/permissions/PermissionSet'; import { Representation } from '../ldp/representation/Representation'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { ContainerManager } from '../storage/ContainerManager'; import { ResourceStore } from '../storage/ResourceStore'; +import { CONTENT_TYPE_QUADS } from '../util/ContentTypes'; +import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError'; +import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { UnauthorizedHttpError } from '../util/errors/UnauthorizedHttpError'; import { ACL, FOAF } from './AclConstants'; +import { AclManager } from './AclManager'; import { Authorizer, AuthorizerArgs } from './Authorizer'; -import { Quad, Store, Term } from 'n3'; /** * Handles most web access control predicates such as diff --git a/src/authorization/SimpleExtensionAclManager.ts b/src/authorization/SimpleExtensionAclManager.ts index b54d40a4b9..dfcf4114b5 100644 --- a/src/authorization/SimpleExtensionAclManager.ts +++ b/src/authorization/SimpleExtensionAclManager.ts @@ -1,5 +1,5 @@ -import { AclManager } from './AclManager'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { AclManager } from './AclManager'; /** * Generates acl URIs by adding an .acl file extension. diff --git a/src/init/Setup.ts b/src/init/Setup.ts index 8a45bbfb0c..4941ec499a 100644 --- a/src/init/Setup.ts +++ b/src/init/Setup.ts @@ -1,9 +1,9 @@ +import streamifyArray from 'streamify-array'; import { AclManager } from '../authorization/AclManager'; -import { DATA_TYPE_BINARY } from '../util/ContentTypes'; import { ExpressHttpServer } from '../server/ExpressHttpServer'; import { ResourceStore } from '../storage/ResourceStore'; +import { DATA_TYPE_BINARY } from '../util/ContentTypes'; import { RuntimeConfig } from './RuntimeConfig'; -import streamifyArray from 'streamify-array'; /** * Invokes all logic to setup a server. diff --git a/src/ldp/AuthenticatedLdpHandler.ts b/src/ldp/AuthenticatedLdpHandler.ts index fc4f162c72..fc2b0156ba 100644 --- a/src/ldp/AuthenticatedLdpHandler.ts +++ b/src/ldp/AuthenticatedLdpHandler.ts @@ -1,16 +1,16 @@ -import { Authorizer } from '../authorization/Authorizer'; import { Credentials } from '../authentication/Credentials'; import { CredentialsExtractor } from '../authentication/CredentialsExtractor'; +import { Authorizer } from '../authorization/Authorizer'; import { HttpHandler } from '../server/HttpHandler'; import { HttpRequest } from '../server/HttpRequest'; import { HttpResponse } from '../server/HttpResponse'; +import { RequestParser } from './http/RequestParser'; +import { ResponseWriter } from './http/ResponseWriter'; import { Operation } from './operations/Operation'; import { OperationHandler } from './operations/OperationHandler'; +import { ResponseDescription } from './operations/ResponseDescription'; import { PermissionSet } from './permissions/PermissionSet'; import { PermissionsExtractor } from './permissions/PermissionsExtractor'; -import { RequestParser } from './http/RequestParser'; -import { ResponseDescription } from './operations/ResponseDescription'; -import { ResponseWriter } from './http/ResponseWriter'; /** * Collection of handlers needed for {@link AuthenticatedLdpHandler} to function. diff --git a/src/ldp/http/AcceptPreferenceParser.ts b/src/ldp/http/AcceptPreferenceParser.ts index 12a04ed97c..2e269a072c 100644 --- a/src/ldp/http/AcceptPreferenceParser.ts +++ b/src/ldp/http/AcceptPreferenceParser.ts @@ -1,7 +1,4 @@ import { HttpRequest } from '../../server/HttpRequest'; -import { PreferenceParser } from './PreferenceParser'; -import { RepresentationPreference } from '../representation/RepresentationPreference'; -import { RepresentationPreferences } from '../representation/RepresentationPreferences'; import { AcceptHeader, parseAccept, @@ -9,6 +6,9 @@ import { parseAcceptEncoding, parseAcceptLanguage, } from '../../util/AcceptParser'; +import { RepresentationPreference } from '../representation/RepresentationPreference'; +import { RepresentationPreferences } from '../representation/RepresentationPreferences'; +import { PreferenceParser } from './PreferenceParser'; /** * Extracts preferences from the accept-* headers from an incoming {@link HttpRequest}. diff --git a/src/ldp/http/BodyParser.ts b/src/ldp/http/BodyParser.ts index c810b354fd..db4149e4bf 100644 --- a/src/ldp/http/BodyParser.ts +++ b/src/ldp/http/BodyParser.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { HttpRequest } from '../../server/HttpRequest'; +import { AsyncHandler } from '../../util/AsyncHandler'; import { Representation } from '../representation/Representation'; /** diff --git a/src/ldp/http/PreferenceParser.ts b/src/ldp/http/PreferenceParser.ts index 61649d1ae2..6e244fb7c4 100644 --- a/src/ldp/http/PreferenceParser.ts +++ b/src/ldp/http/PreferenceParser.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { HttpRequest } from '../../server/HttpRequest'; +import { AsyncHandler } from '../../util/AsyncHandler'; import { RepresentationPreferences } from '../representation/RepresentationPreferences'; /** diff --git a/src/ldp/http/RequestParser.ts b/src/ldp/http/RequestParser.ts index 90c82926a0..e1cbb5140f 100644 --- a/src/ldp/http/RequestParser.ts +++ b/src/ldp/http/RequestParser.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { HttpRequest } from '../../server/HttpRequest'; +import { AsyncHandler } from '../../util/AsyncHandler'; import { Operation } from '../operations/Operation'; /** diff --git a/src/ldp/http/ResponseWriter.ts b/src/ldp/http/ResponseWriter.ts index 52b4db3adf..b4c50b42fa 100644 --- a/src/ldp/http/ResponseWriter.ts +++ b/src/ldp/http/ResponseWriter.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { HttpResponse } from '../../server/HttpResponse'; +import { AsyncHandler } from '../../util/AsyncHandler'; import { ResponseDescription } from '../operations/ResponseDescription'; /** diff --git a/src/ldp/http/SimpleBodyParser.ts b/src/ldp/http/SimpleBodyParser.ts index cd794dc7ad..a62ad094df 100644 --- a/src/ldp/http/SimpleBodyParser.ts +++ b/src/ldp/http/SimpleBodyParser.ts @@ -1,8 +1,8 @@ -import { BinaryRepresentation } from '../representation/BinaryRepresentation'; -import { BodyParser } from './BodyParser'; -import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; import { HttpRequest } from '../../server/HttpRequest'; +import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; +import { BinaryRepresentation } from '../representation/BinaryRepresentation'; import { RepresentationMetadata } from '../representation/RepresentationMetadata'; +import { BodyParser } from './BodyParser'; /** * Converts incoming {@link HttpRequest} to a Representation without any further parsing. diff --git a/src/ldp/http/SimpleRequestParser.ts b/src/ldp/http/SimpleRequestParser.ts index 4bdbc8d29d..a7b1add5d6 100644 --- a/src/ldp/http/SimpleRequestParser.ts +++ b/src/ldp/http/SimpleRequestParser.ts @@ -1,6 +1,6 @@ -import { BodyParser } from './BodyParser'; import { HttpRequest } from '../../server/HttpRequest'; import { Operation } from '../operations/Operation'; +import { BodyParser } from './BodyParser'; import { PreferenceParser } from './PreferenceParser'; import { RequestParser } from './RequestParser'; import { TargetExtractor } from './TargetExtractor'; diff --git a/src/ldp/http/SimpleResponseWriter.ts b/src/ldp/http/SimpleResponseWriter.ts index 410317f499..78e621aa5f 100644 --- a/src/ldp/http/SimpleResponseWriter.ts +++ b/src/ldp/http/SimpleResponseWriter.ts @@ -1,9 +1,9 @@ +import { HttpResponse } from '../../server/HttpResponse'; import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; import { HttpError } from '../../util/errors/HttpError'; -import { HttpResponse } from '../../server/HttpResponse'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { ResponseDescription } from '../operations/ResponseDescription'; import { ResponseWriter } from './ResponseWriter'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Writes to an {@link HttpResponse} based on the incoming {@link ResponseDescription} or error. diff --git a/src/ldp/http/SimpleSparqlUpdateBodyParser.ts b/src/ldp/http/SimpleSparqlUpdateBodyParser.ts index 0132041878..472bf0694d 100644 --- a/src/ldp/http/SimpleSparqlUpdateBodyParser.ts +++ b/src/ldp/http/SimpleSparqlUpdateBodyParser.ts @@ -1,12 +1,12 @@ -import { BodyParser } from './BodyParser'; -import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; -import { HttpRequest } from '../../server/HttpRequest'; import { PassThrough } from 'stream'; -import { readableToString } from '../../util/Util'; -import { SparqlUpdatePatch } from './SparqlUpdatePatch'; import { translate } from 'sparqlalgebrajs'; +import { HttpRequest } from '../../server/HttpRequest'; +import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError'; +import { readableToString } from '../../util/Util'; +import { BodyParser } from './BodyParser'; +import { SparqlUpdatePatch } from './SparqlUpdatePatch'; /** * {@link BodyParser} that supports `application/sparql-update` content. diff --git a/src/ldp/http/SimpleTargetExtractor.ts b/src/ldp/http/SimpleTargetExtractor.ts index 60320305fe..fe1c6b0215 100644 --- a/src/ldp/http/SimpleTargetExtractor.ts +++ b/src/ldp/http/SimpleTargetExtractor.ts @@ -1,8 +1,8 @@ +import { TLSSocket } from 'tls'; import { format } from 'url'; import { HttpRequest } from '../../server/HttpRequest'; import { ResourceIdentifier } from '../representation/ResourceIdentifier'; import { TargetExtractor } from './TargetExtractor'; -import { TLSSocket } from 'tls'; /** * Extracts an identifier from an incoming {@link HttpRequest}. diff --git a/src/ldp/http/TargetExtractor.ts b/src/ldp/http/TargetExtractor.ts index 6c758c8103..0c8cf167c1 100644 --- a/src/ldp/http/TargetExtractor.ts +++ b/src/ldp/http/TargetExtractor.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { HttpRequest } from '../../server/HttpRequest'; +import { AsyncHandler } from '../../util/AsyncHandler'; import { ResourceIdentifier } from '../representation/ResourceIdentifier'; /** diff --git a/src/ldp/operations/SimpleDeleteOperationHandler.ts b/src/ldp/operations/SimpleDeleteOperationHandler.ts index de1cf2bd28..6a270d3df0 100644 --- a/src/ldp/operations/SimpleDeleteOperationHandler.ts +++ b/src/ldp/operations/SimpleDeleteOperationHandler.ts @@ -1,8 +1,8 @@ +import { ResourceStore } from '../../storage/ResourceStore'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResourceStore } from '../../storage/ResourceStore'; import { ResponseDescription } from './ResponseDescription'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Handles DELETE {@link Operation}s. diff --git a/src/ldp/operations/SimpleGetOperationHandler.ts b/src/ldp/operations/SimpleGetOperationHandler.ts index 634e9138d7..0b810d1dc7 100644 --- a/src/ldp/operations/SimpleGetOperationHandler.ts +++ b/src/ldp/operations/SimpleGetOperationHandler.ts @@ -1,8 +1,8 @@ +import { ResourceStore } from '../../storage/ResourceStore'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResourceStore } from '../../storage/ResourceStore'; import { ResponseDescription } from './ResponseDescription'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Handles GET {@link Operation}s. diff --git a/src/ldp/operations/SimplePatchOperationHandler.ts b/src/ldp/operations/SimplePatchOperationHandler.ts index 532ed52813..56823e6011 100644 --- a/src/ldp/operations/SimplePatchOperationHandler.ts +++ b/src/ldp/operations/SimplePatchOperationHandler.ts @@ -1,9 +1,9 @@ +import { ResourceStore } from '../../storage/ResourceStore'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; +import { Patch } from '../http/Patch'; import { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { Patch } from '../http/Patch'; -import { ResourceStore } from '../../storage/ResourceStore'; import { ResponseDescription } from './ResponseDescription'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; export class SimplePatchOperationHandler extends OperationHandler { private readonly store: ResourceStore; diff --git a/src/ldp/operations/SimplePostOperationHandler.ts b/src/ldp/operations/SimplePostOperationHandler.ts index d65eb3edbd..a484370f22 100644 --- a/src/ldp/operations/SimplePostOperationHandler.ts +++ b/src/ldp/operations/SimplePostOperationHandler.ts @@ -1,8 +1,8 @@ +import { ResourceStore } from '../../storage/ResourceStore'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResourceStore } from '../../storage/ResourceStore'; import { ResponseDescription } from './ResponseDescription'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Handles POST {@link Operation}s. diff --git a/src/ldp/operations/SimplePutOperationHandler.ts b/src/ldp/operations/SimplePutOperationHandler.ts index 3dc9bceb52..28821cfcd9 100644 --- a/src/ldp/operations/SimplePutOperationHandler.ts +++ b/src/ldp/operations/SimplePutOperationHandler.ts @@ -1,8 +1,8 @@ +import { ResourceStore } from '../../storage/ResourceStore'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResourceStore } from '../../storage/ResourceStore'; import { ResponseDescription } from './ResponseDescription'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Handles PUT {@link Operation}s. diff --git a/src/ldp/permissions/BasePermissionsExtractor.ts b/src/ldp/permissions/BasePermissionsExtractor.ts index e6fd0c53b7..944f254e3d 100644 --- a/src/ldp/permissions/BasePermissionsExtractor.ts +++ b/src/ldp/permissions/BasePermissionsExtractor.ts @@ -1,7 +1,7 @@ +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { Operation } from '../operations/Operation'; import { PermissionSet } from './PermissionSet'; import { PermissionsExtractor } from './PermissionsExtractor'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Generates permissions for the base set of methods that always require the same permissions. diff --git a/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts b/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts index da0aaeeb1a..903e706486 100644 --- a/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts +++ b/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts @@ -1,10 +1,10 @@ import { Algebra } from 'sparqlalgebrajs'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; +import { SparqlUpdatePatch } from '../http/SparqlUpdatePatch'; import { Operation } from '../operations/Operation'; +import { Representation } from '../representation/Representation'; import { PermissionSet } from './PermissionSet'; import { PermissionsExtractor } from './PermissionsExtractor'; -import { Representation } from '../representation/Representation'; -import { SparqlUpdatePatch } from '../http/SparqlUpdatePatch'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; /** * Generates permissions for a SPARQL DELETE/INSERT patch. diff --git a/src/server/ExpressHttpServer.ts b/src/server/ExpressHttpServer.ts index d5e5051b97..7c6433d871 100644 --- a/src/server/ExpressHttpServer.ts +++ b/src/server/ExpressHttpServer.ts @@ -1,7 +1,7 @@ +import { Server } from 'http'; import cors from 'cors'; import express from 'express'; import { HttpHandler } from './HttpHandler'; -import { Server } from 'http'; export class ExpressHttpServer { private readonly handler: HttpHandler; diff --git a/src/storage/FileResourceStore.ts b/src/storage/FileResourceStore.ts index d04cef932a..531f13b273 100644 --- a/src/storage/FileResourceStore.ts +++ b/src/storage/FileResourceStore.ts @@ -1,23 +1,23 @@ +import { createReadStream, createWriteStream, promises as fsPromises, Stats } from 'fs'; +import { posix } from 'path'; +import { Readable } from 'stream'; import arrayifyStream from 'arrayify-stream'; -import { ConflictHttpError } from '../util/errors/ConflictHttpError'; import { contentType as getContentTypeFromExtension } from 'mime-types'; -import { InteractionController } from '../util/InteractionController'; -import { MetadataController } from '../util/MetadataController'; -import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError'; -import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; -import { posix } from 'path'; import { Quad } from 'rdf-js'; -import { Readable } from 'stream'; +import streamifyArray from 'streamify-array'; +import { RuntimeConfig } from '../init/RuntimeConfig'; import { Representation } from '../ldp/representation/Representation'; import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { ResourceStore } from './ResourceStore'; -import { RuntimeConfig } from '../init/RuntimeConfig'; -import streamifyArray from 'streamify-array'; -import { UnsupportedMediaTypeHttpError } from '../util/errors/UnsupportedMediaTypeHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../util/ContentTypes'; -import { createReadStream, createWriteStream, promises as fsPromises, Stats } from 'fs'; +import { ConflictHttpError } from '../util/errors/ConflictHttpError'; +import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError'; +import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; +import { UnsupportedMediaTypeHttpError } from '../util/errors/UnsupportedMediaTypeHttpError'; +import { InteractionController } from '../util/InteractionController'; +import { MetadataController } from '../util/MetadataController'; import { ensureTrailingSlash, trimTrailingSlashes } from '../util/Util'; +import { ResourceStore } from './ResourceStore'; const { extname, join: joinPath, normalize: normalizePath } = posix; diff --git a/src/storage/LockingResourceStore.ts b/src/storage/LockingResourceStore.ts index be4921a4a9..30d414bb3a 100644 --- a/src/storage/LockingResourceStore.ts +++ b/src/storage/LockingResourceStore.ts @@ -1,10 +1,10 @@ -import { AtomicResourceStore } from './AtomicResourceStore'; -import { Conditions } from './Conditions'; -import { Patch } from '../ldp/http/Patch'; import { Readable } from 'stream'; +import { Patch } from '../ldp/http/Patch'; import { Representation } from '../ldp/representation/Representation'; import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { AtomicResourceStore } from './AtomicResourceStore'; +import { Conditions } from './Conditions'; import { ResourceLocker } from './ResourceLocker'; import { ResourceStore } from './ResourceStore'; diff --git a/src/storage/PassthroughStore.ts b/src/storage/PassthroughStore.ts index 869b56cceb..0c261a3013 100644 --- a/src/storage/PassthroughStore.ts +++ b/src/storage/PassthroughStore.ts @@ -1,8 +1,8 @@ -import { Conditions } from './Conditions'; import { Patch } from '../ldp/http/Patch'; import { Representation } from '../ldp/representation/Representation'; import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { Conditions } from './Conditions'; import { ResourceStore } from './ResourceStore'; /** diff --git a/src/storage/PatchingStore.ts b/src/storage/PatchingStore.ts index ec61859f63..b71cc7d23e 100644 --- a/src/storage/PatchingStore.ts +++ b/src/storage/PatchingStore.ts @@ -1,8 +1,8 @@ +import { Patch } from '../ldp/http/Patch'; +import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { Conditions } from './Conditions'; import { PassthroughStore } from './PassthroughStore'; -import { Patch } from '../ldp/http/Patch'; import { PatchHandler } from './patch/PatchHandler'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { ResourceStore } from './ResourceStore'; /** diff --git a/src/storage/RepresentationConvertingStore.ts b/src/storage/RepresentationConvertingStore.ts index e34dfa507c..203149fba9 100644 --- a/src/storage/RepresentationConvertingStore.ts +++ b/src/storage/RepresentationConvertingStore.ts @@ -1,10 +1,10 @@ -import { Conditions } from './Conditions'; -import { matchingMediaType } from '../util/Util'; -import { PassthroughStore } from './PassthroughStore'; import { Representation } from '../ldp/representation/Representation'; -import { RepresentationConverter } from './conversion/RepresentationConverter'; import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { matchingMediaType } from '../util/Util'; +import { Conditions } from './Conditions'; +import { RepresentationConverter } from './conversion/RepresentationConverter'; +import { PassthroughStore } from './PassthroughStore'; import { ResourceStore } from './ResourceStore'; /** diff --git a/src/storage/ResourceLocker.ts b/src/storage/ResourceLocker.ts index 8964fd0500..2b25adb9b5 100644 --- a/src/storage/ResourceLocker.ts +++ b/src/storage/ResourceLocker.ts @@ -1,5 +1,5 @@ -import { Lock } from './Lock'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { Lock } from './Lock'; /** * Allows the locking of resources which is needed for non-atomic {@link ResourceStore}s. diff --git a/src/storage/ResourceStore.ts b/src/storage/ResourceStore.ts index dcdff55ccf..353ec7932e 100644 --- a/src/storage/ResourceStore.ts +++ b/src/storage/ResourceStore.ts @@ -1,8 +1,8 @@ -import { Conditions } from './Conditions'; import { Patch } from '../ldp/http/Patch'; import { Representation } from '../ldp/representation/Representation'; import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { Conditions } from './Conditions'; /** * A ResourceStore represents a collection of resources. diff --git a/src/storage/SimpleResourceStore.ts b/src/storage/SimpleResourceStore.ts index 2fae99a55e..739cf3a5b6 100644 --- a/src/storage/SimpleResourceStore.ts +++ b/src/storage/SimpleResourceStore.ts @@ -1,12 +1,12 @@ import arrayifyStream from 'arrayify-stream'; -import { DATA_TYPE_BINARY } from '../util/ContentTypes'; -import { ensureTrailingSlash } from '../util/Util'; -import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; +import streamifyArray from 'streamify-array'; +import { RuntimeConfig } from '../init/RuntimeConfig'; import { Representation } from '../ldp/representation/Representation'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { DATA_TYPE_BINARY } from '../util/ContentTypes'; +import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; +import { ensureTrailingSlash } from '../util/Util'; import { ResourceStore } from './ResourceStore'; -import { RuntimeConfig } from '../init/RuntimeConfig'; -import streamifyArray from 'streamify-array'; /** * Resource store storing its data in an in-memory map. diff --git a/src/storage/SingleThreadedResourceLocker.ts b/src/storage/SingleThreadedResourceLocker.ts index bebaa9d9d0..da800b373b 100644 --- a/src/storage/SingleThreadedResourceLocker.ts +++ b/src/storage/SingleThreadedResourceLocker.ts @@ -1,6 +1,6 @@ import AsyncLock from 'async-lock'; -import { Lock } from './Lock'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { Lock } from './Lock'; import { ResourceLocker } from './ResourceLocker'; /** diff --git a/src/storage/UrlContainerManager.ts b/src/storage/UrlContainerManager.ts index 07a1435f12..c6e491c1cc 100644 --- a/src/storage/UrlContainerManager.ts +++ b/src/storage/UrlContainerManager.ts @@ -1,7 +1,7 @@ -import { ContainerManager } from './ContainerManager'; -import { ensureTrailingSlash } from '../util/Util'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { RuntimeConfig } from '../init/RuntimeConfig'; +import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import { ensureTrailingSlash } from '../util/Util'; +import { ContainerManager } from './ContainerManager'; /** * Determines containers based on URL decomposition. diff --git a/src/storage/conversion/ConversionUtil.ts b/src/storage/conversion/ConversionUtil.ts index 5f18c1b68e..0d2921f6bf 100644 --- a/src/storage/conversion/ConversionUtil.ts +++ b/src/storage/conversion/ConversionUtil.ts @@ -1,8 +1,8 @@ -import { matchingMediaType } from '../../util/Util'; -import { RepresentationConverterArgs } from './RepresentationConverter'; import { RepresentationPreference } from '../../ldp/representation/RepresentationPreference'; import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; +import { matchingMediaType } from '../../util/Util'; +import { RepresentationConverterArgs } from './RepresentationConverter'; /** * Filters out the media types from the preferred types that correspond to one of the supported types. diff --git a/src/storage/conversion/QuadToTurtleConverter.ts b/src/storage/conversion/QuadToTurtleConverter.ts index 2e95baea61..4187bad4a4 100644 --- a/src/storage/conversion/QuadToTurtleConverter.ts +++ b/src/storage/conversion/QuadToTurtleConverter.ts @@ -1,8 +1,8 @@ -import { checkRequest } from './ConversionUtil'; +import { StreamWriter } from 'n3'; import { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; -import { StreamWriter } from 'n3'; import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../util/ContentTypes'; +import { checkRequest } from './ConversionUtil'; import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter'; /** diff --git a/src/storage/conversion/RepresentationConverter.ts b/src/storage/conversion/RepresentationConverter.ts index 8b7c403076..fd33365018 100644 --- a/src/storage/conversion/RepresentationConverter.ts +++ b/src/storage/conversion/RepresentationConverter.ts @@ -1,7 +1,7 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { Representation } from '../../ldp/representation/Representation'; import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import { AsyncHandler } from '../../util/AsyncHandler'; export interface RepresentationConverterArgs { /** diff --git a/src/storage/conversion/TurtleToQuadConverter.ts b/src/storage/conversion/TurtleToQuadConverter.ts index 112d023f27..d97b00fe0f 100644 --- a/src/storage/conversion/TurtleToQuadConverter.ts +++ b/src/storage/conversion/TurtleToQuadConverter.ts @@ -1,10 +1,10 @@ -import { checkRequest } from './ConversionUtil'; import { PassThrough } from 'stream'; +import { StreamParser } from 'n3'; import { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; -import { StreamParser } from 'n3'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; +import { checkRequest } from './ConversionUtil'; import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter'; /** diff --git a/src/storage/patch/PatchHandler.ts b/src/storage/patch/PatchHandler.ts index 9ef49b6a36..fdb7ba4928 100644 --- a/src/storage/patch/PatchHandler.ts +++ b/src/storage/patch/PatchHandler.ts @@ -1,5 +1,5 @@ -import { AsyncHandler } from '../../util/AsyncHandler'; import { Patch } from '../../ldp/http/Patch'; import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import { AsyncHandler } from '../../util/AsyncHandler'; export abstract class PatchHandler extends AsyncHandler<{identifier: ResourceIdentifier; patch: Patch}> {} diff --git a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts b/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts index e39cb7efcb..c3e82a7761 100644 --- a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts +++ b/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts @@ -1,17 +1,17 @@ -import { Algebra } from 'sparqlalgebrajs'; -import { BaseQuad } from 'rdf-js'; -import { defaultGraph } from '@rdfjs/data-model'; -import { PatchHandler } from './PatchHandler'; import { Readable } from 'stream'; +import { defaultGraph } from '@rdfjs/data-model'; +import { Store } from 'n3'; +import { BaseQuad } from 'rdf-js'; +import { someTerms } from 'rdf-terms'; +import { Algebra } from 'sparqlalgebrajs'; +import { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch'; import { Representation } from '../../ldp/representation/Representation'; import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { ResourceLocker } from '../ResourceLocker'; import { ResourceStore } from '../ResourceStore'; -import { someTerms } from 'rdf-terms'; -import { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch'; -import { Store } from 'n3'; -import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes'; +import { PatchHandler } from './PatchHandler'; /** * PatchHandler that supports specific types of SPARQL updates. diff --git a/src/util/InteractionController.ts b/src/util/InteractionController.ts index e37c2553e4..185b0bddd7 100644 --- a/src/util/InteractionController.ts +++ b/src/util/InteractionController.ts @@ -1,6 +1,6 @@ -import { trimTrailingSlashes } from './Util'; import { v4 as uuid } from 'uuid'; import { LINK_TYPE_LDP_BC, LINK_TYPE_LDPC } from './LinkTypes'; +import { trimTrailingSlashes } from './Util'; export class InteractionController { /** diff --git a/src/util/MetadataController.ts b/src/util/MetadataController.ts index d5d7add3ce..dcf8093c77 100644 --- a/src/util/MetadataController.ts +++ b/src/util/MetadataController.ts @@ -1,10 +1,10 @@ -import arrayifyStream from 'arrayify-stream'; -import { Readable } from 'stream'; import { Stats } from 'fs'; -import streamifyArray from 'streamify-array'; +import { Readable } from 'stream'; +import arrayifyStream from 'arrayify-stream'; import { DataFactory, StreamParser, StreamWriter } from 'n3'; -import { LDP, RDF, STAT, TERMS, XML } from './Prefixes'; import { NamedNode, Quad } from 'rdf-js'; +import streamifyArray from 'streamify-array'; +import { LDP, RDF, STAT, TERMS, XML } from './Prefixes'; export const TYPE_PREDICATE = DataFactory.namedNode(`${RDF}type`); export const MODIFIED_PREDICATE = DataFactory.namedNode(`${TERMS}modified`); diff --git a/src/util/Util.ts b/src/util/Util.ts index dd06286da1..0dcbaa5a52 100644 --- a/src/util/Util.ts +++ b/src/util/Util.ts @@ -1,5 +1,5 @@ -import arrayifyStream from 'arrayify-stream'; import { Readable } from 'stream'; +import arrayifyStream from 'arrayify-stream'; /** * Makes sure the input path has exactly 1 slash at the end. diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index 41238e1fc6..984d9cc5fd 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -1,37 +1,37 @@ -import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; +import * as url from 'url'; +import { namedNode, quad } from '@rdfjs/data-model'; +import { Parser } from 'n3'; +import { MockResponse } from 'node-mocks-http'; +import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; +import { SimpleAuthorizer } from '../../src/authorization/SimpleAuthorizer'; +import { RuntimeConfig } from '../../src/init/RuntimeConfig'; import { AuthenticatedLdpHandler } from '../../src/ldp/AuthenticatedLdpHandler'; -import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; +import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; import { BodyParser } from '../../src/ldp/http/BodyParser'; -import { call } from '../util/Util'; -import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler'; -import { HttpRequest } from '../../src/server/HttpRequest'; -import { MockResponse } from 'node-mocks-http'; +import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; +import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser'; +import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter'; +import { SimpleSparqlUpdateBodyParser } from '../../src/ldp/http/SimpleSparqlUpdateBodyParser'; +import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor'; import { Operation } from '../../src/ldp/operations/Operation'; -import { Parser } from 'n3'; -import { PatchingStore } from '../../src/storage/PatchingStore'; -import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter'; -import { Representation } from '../../src/ldp/representation/Representation'; -import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription'; -import { RuntimeConfig } from '../../src/init/RuntimeConfig'; -import { SimpleAuthorizer } from '../../src/authorization/SimpleAuthorizer'; -import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; -import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; import { SimpleDeleteOperationHandler } from '../../src/ldp/operations/SimpleDeleteOperationHandler'; import { SimpleGetOperationHandler } from '../../src/ldp/operations/SimpleGetOperationHandler'; import { SimplePatchOperationHandler } from '../../src/ldp/operations/SimplePatchOperationHandler'; import { SimplePostOperationHandler } from '../../src/ldp/operations/SimplePostOperationHandler'; -import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser'; -import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore'; -import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter'; -import { SimpleSparqlUpdateBodyParser } from '../../src/ldp/http/SimpleSparqlUpdateBodyParser'; -import { SimpleSparqlUpdatePatchHandler } from '../../src/storage/patch/SimpleSparqlUpdatePatchHandler'; -import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor'; -import { SingleThreadedResourceLocker } from '../../src/storage/SingleThreadedResourceLocker'; +import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; import { SparqlPatchPermissionsExtractor } from '../../src/ldp/permissions/SparqlPatchPermissionsExtractor'; +import { Representation } from '../../src/ldp/representation/Representation'; +import { HttpRequest } from '../../src/server/HttpRequest'; +import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter'; import { TurtleToQuadConverter } from '../../src/storage/conversion/TurtleToQuadConverter'; -import { namedNode, quad } from '@rdfjs/data-model'; -import * as url from 'url'; +import { SimpleSparqlUpdatePatchHandler } from '../../src/storage/patch/SimpleSparqlUpdatePatchHandler'; +import { PatchingStore } from '../../src/storage/PatchingStore'; +import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; +import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore'; +import { SingleThreadedResourceLocker } from '../../src/storage/SingleThreadedResourceLocker'; +import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler'; +import { call } from '../util/Util'; describe('An integrated AuthenticatedLdpHandler', (): void => { describe('with simple handlers', (): void => { diff --git a/test/integration/Authorization.test.ts b/test/integration/Authorization.test.ts index aa3dd809b2..73badc9411 100644 --- a/test/integration/Authorization.test.ts +++ b/test/integration/Authorization.test.ts @@ -1,33 +1,33 @@ -import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; +import { MockResponse } from 'node-mocks-http'; +import streamifyArray from 'streamify-array'; +import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; +import { SimpleAclAuthorizer } from '../../src/authorization/SimpleAclAuthorizer'; +import { SimpleExtensionAclManager } from '../../src/authorization/SimpleExtensionAclManager'; +import { RuntimeConfig } from '../../src/init/RuntimeConfig'; import { AuthenticatedLdpHandler } from '../../src/ldp/AuthenticatedLdpHandler'; -import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; +import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; import { BodyParser } from '../../src/ldp/http/BodyParser'; -import { call } from '../util/Util'; -import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler'; -import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes'; -import { MockResponse } from 'node-mocks-http'; +import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; +import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser'; +import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter'; +import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor'; import { Operation } from '../../src/ldp/operations/Operation'; -import { PermissionSet } from '../../src/ldp/permissions/PermissionSet'; -import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter'; -import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; -import { ResourceStore } from '../../src/storage/ResourceStore'; import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription'; -import { RuntimeConfig } from '../../src/init/RuntimeConfig'; -import { SimpleAclAuthorizer } from '../../src/authorization/SimpleAclAuthorizer'; -import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; -import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor'; import { SimpleDeleteOperationHandler } from '../../src/ldp/operations/SimpleDeleteOperationHandler'; -import { SimpleExtensionAclManager } from '../../src/authorization/SimpleExtensionAclManager'; import { SimpleGetOperationHandler } from '../../src/ldp/operations/SimpleGetOperationHandler'; import { SimplePostOperationHandler } from '../../src/ldp/operations/SimplePostOperationHandler'; import { SimplePutOperationHandler } from '../../src/ldp/operations/SimplePutOperationHandler'; -import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser'; -import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore'; -import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter'; -import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor'; -import streamifyArray from 'streamify-array'; +import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; +import { PermissionSet } from '../../src/ldp/permissions/PermissionSet'; +import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter'; import { TurtleToQuadConverter } from '../../src/storage/conversion/TurtleToQuadConverter'; +import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore'; +import { ResourceStore } from '../../src/storage/ResourceStore'; +import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore'; import { UrlContainerManager } from '../../src/storage/UrlContainerManager'; +import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler'; +import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes'; +import { call } from '../util/Util'; const setAcl = async(store: ResourceStore, id: string, permissions: PermissionSet, control: boolean, access: boolean, def: boolean, agent?: string, agentClass?: 'agent' | 'authenticated'): Promise => { diff --git a/test/integration/RequestParser.test.ts b/test/integration/RequestParser.test.ts index 5a006218a0..76fb6392d1 100644 --- a/test/integration/RequestParser.test.ts +++ b/test/integration/RequestParser.test.ts @@ -1,12 +1,12 @@ -import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; -import arrayifyStream from 'arrayify-stream'; -import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes'; -import { HttpRequest } from '../../src/server/HttpRequest'; import { Readable } from 'stream'; +import arrayifyStream from 'arrayify-stream'; +import streamifyArray from 'streamify-array'; +import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser'; import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser'; import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser'; import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor'; -import streamifyArray from 'streamify-array'; +import { HttpRequest } from '../../src/server/HttpRequest'; +import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes'; describe('A SimpleRequestParser with simple input parsers', (): void => { const targetExtractor = new SimpleTargetExtractor(); diff --git a/test/unit/authentication/SimpleCredentialsExtractor.test.ts b/test/unit/authentication/SimpleCredentialsExtractor.test.ts index 149c649765..3d97d41701 100644 --- a/test/unit/authentication/SimpleCredentialsExtractor.test.ts +++ b/test/unit/authentication/SimpleCredentialsExtractor.test.ts @@ -1,5 +1,5 @@ -import { HttpRequest } from '../../../src/server/HttpRequest'; import { SimpleCredentialsExtractor } from '../../../src/authentication/SimpleCredentialsExtractor'; +import { HttpRequest } from '../../../src/server/HttpRequest'; describe('A SimpleCredentialsExtractor', (): void => { const extractor = new SimpleCredentialsExtractor(); diff --git a/test/unit/authorization/SimpleAclAuthorizer.test.ts b/test/unit/authorization/SimpleAclAuthorizer.test.ts index 26c46c39e8..d5e0cc9676 100644 --- a/test/unit/authorization/SimpleAclAuthorizer.test.ts +++ b/test/unit/authorization/SimpleAclAuthorizer.test.ts @@ -1,16 +1,16 @@ -import { AclManager } from '../../../src/authorization/AclManager'; -import { ContainerManager } from '../../../src/storage/ContainerManager'; +import { namedNode, quad } from '@rdfjs/data-model'; +import streamifyArray from 'streamify-array'; import { Credentials } from '../../../src/authentication/Credentials'; -import { ForbiddenHttpError } from '../../../src/util/errors/ForbiddenHttpError'; -import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; +import { AclManager } from '../../../src/authorization/AclManager'; +import { SimpleAclAuthorizer } from '../../../src/authorization/SimpleAclAuthorizer'; import { PermissionSet } from '../../../src/ldp/permissions/PermissionSet'; import { Representation } from '../../../src/ldp/representation/Representation'; import { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier'; +import { ContainerManager } from '../../../src/storage/ContainerManager'; import { ResourceStore } from '../../../src/storage/ResourceStore'; -import { SimpleAclAuthorizer } from '../../../src/authorization/SimpleAclAuthorizer'; -import streamifyArray from 'streamify-array'; +import { ForbiddenHttpError } from '../../../src/util/errors/ForbiddenHttpError'; +import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; import { UnauthorizedHttpError } from '../../../src/util/errors/UnauthorizedHttpError'; -import { namedNode, quad } from '@rdfjs/data-model'; const nn = namedNode; diff --git a/test/unit/ldp/AuthenticatedLdpHandler.test.ts b/test/unit/ldp/AuthenticatedLdpHandler.test.ts index 4f2709e30c..12e95be0df 100644 --- a/test/unit/ldp/AuthenticatedLdpHandler.test.ts +++ b/test/unit/ldp/AuthenticatedLdpHandler.test.ts @@ -1,14 +1,14 @@ -import { Authorizer } from '../../../src/authorization/Authorizer'; import { CredentialsExtractor } from '../../../src/authentication/CredentialsExtractor'; -import { HttpRequest } from '../../../src/server/HttpRequest'; -import { HttpResponse } from '../../../src/server/HttpResponse'; +import { Authorizer } from '../../../src/authorization/Authorizer'; +import { AuthenticatedLdpHandler, AuthenticatedLdpHandlerArgs } from '../../../src/ldp/AuthenticatedLdpHandler'; +import { RequestParser } from '../../../src/ldp/http/RequestParser'; +import { ResponseWriter } from '../../../src/ldp/http/ResponseWriter'; import { Operation } from '../../../src/ldp/operations/Operation'; import { OperationHandler } from '../../../src/ldp/operations/OperationHandler'; import { PermissionsExtractor } from '../../../src/ldp/permissions/PermissionsExtractor'; -import { RequestParser } from '../../../src/ldp/http/RequestParser'; -import { ResponseWriter } from '../../../src/ldp/http/ResponseWriter'; +import { HttpRequest } from '../../../src/server/HttpRequest'; +import { HttpResponse } from '../../../src/server/HttpResponse'; import { StaticAsyncHandler } from '../../util/StaticAsyncHandler'; -import { AuthenticatedLdpHandler, AuthenticatedLdpHandlerArgs } from '../../../src/ldp/AuthenticatedLdpHandler'; describe('An AuthenticatedLdpHandler', (): void => { let args: AuthenticatedLdpHandlerArgs; diff --git a/test/unit/ldp/http/SimpleBodyParser.test.ts b/test/unit/ldp/http/SimpleBodyParser.test.ts index 86eec302aa..8f91f7ac77 100644 --- a/test/unit/ldp/http/SimpleBodyParser.test.ts +++ b/test/unit/ldp/http/SimpleBodyParser.test.ts @@ -1,9 +1,9 @@ -import arrayifyStream from 'arrayify-stream'; -import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; -import { HttpRequest } from '../../../../src/server/HttpRequest'; import { Readable } from 'stream'; -import { SimpleBodyParser } from '../../../../src/ldp/http/SimpleBodyParser'; +import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; +import { SimpleBodyParser } from '../../../../src/ldp/http/SimpleBodyParser'; +import { HttpRequest } from '../../../../src/server/HttpRequest'; +import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; import 'jest-rdf'; describe('A SimpleBodyparser', (): void => { diff --git a/test/unit/ldp/http/SimpleRequestParser.test.ts b/test/unit/ldp/http/SimpleRequestParser.test.ts index 0a74f2567d..b69578717f 100644 --- a/test/unit/ldp/http/SimpleRequestParser.test.ts +++ b/test/unit/ldp/http/SimpleRequestParser.test.ts @@ -1,8 +1,8 @@ import { BodyParser } from '../../../../src/ldp/http/BodyParser'; import { PreferenceParser } from '../../../../src/ldp/http/PreferenceParser'; import { SimpleRequestParser } from '../../../../src/ldp/http/SimpleRequestParser'; -import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler'; import { TargetExtractor } from '../../../../src/ldp/http/TargetExtractor'; +import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler'; describe('A SimpleRequestParser', (): void => { let targetExtractor: TargetExtractor; diff --git a/test/unit/ldp/http/SimpleResponseWriter.test.ts b/test/unit/ldp/http/SimpleResponseWriter.test.ts index 91be497cee..c667679026 100644 --- a/test/unit/ldp/http/SimpleResponseWriter.test.ts +++ b/test/unit/ldp/http/SimpleResponseWriter.test.ts @@ -1,11 +1,11 @@ import { EventEmitter } from 'events'; +import { createResponse, MockResponse } from 'node-mocks-http'; import { Quad } from 'rdf-js'; -import { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription'; -import { SimpleResponseWriter } from '../../../../src/ldp/http/SimpleResponseWriter'; import streamifyArray from 'streamify-array'; -import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; -import { createResponse, MockResponse } from 'node-mocks-http'; +import { SimpleResponseWriter } from '../../../../src/ldp/http/SimpleResponseWriter'; +import { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription'; import { DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes'; +import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimpleResponseWriter', (): void => { const writer = new SimpleResponseWriter(); diff --git a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts b/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts index 3981ae1fef..732d084cba 100644 --- a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts +++ b/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts @@ -1,12 +1,12 @@ -import { Algebra } from 'sparqlalgebrajs'; +import { namedNode, quad } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; -import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; -import { HttpRequest } from '../../../../src/server/HttpRequest'; -import { SimpleSparqlUpdateBodyParser } from '../../../../src/ldp/http/SimpleSparqlUpdateBodyParser'; +import { Algebra } from 'sparqlalgebrajs'; import streamifyArray from 'streamify-array'; +import { SimpleSparqlUpdateBodyParser } from '../../../../src/ldp/http/SimpleSparqlUpdateBodyParser'; +import { HttpRequest } from '../../../../src/server/HttpRequest'; +import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError'; -import { namedNode, quad } from '@rdfjs/data-model'; describe('A SimpleSparqlUpdateBodyParser', (): void => { const bodyParser = new SimpleSparqlUpdateBodyParser(); diff --git a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts b/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts index 2fadd71607..44af63f2f9 100644 --- a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts @@ -1,6 +1,6 @@ import { Operation } from '../../../../src/ldp/operations/Operation'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { SimpleDeleteOperationHandler } from '../../../../src/ldp/operations/SimpleDeleteOperationHandler'; +import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimpleDeleteOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts b/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts index b78a58a3e6..4c2b46ead6 100644 --- a/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts @@ -1,8 +1,8 @@ -import { DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes'; import { Operation } from '../../../../src/ldp/operations/Operation'; +import { SimpleGetOperationHandler } from '../../../../src/ldp/operations/SimpleGetOperationHandler'; import { Representation } from '../../../../src/ldp/representation/Representation'; import { ResourceStore } from '../../../../src/storage/ResourceStore'; -import { SimpleGetOperationHandler } from '../../../../src/ldp/operations/SimpleGetOperationHandler'; +import { DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimpleGetOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts b/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts index 1b51b1c967..06e8d914c2 100644 --- a/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts @@ -1,6 +1,6 @@ import { Operation } from '../../../../src/ldp/operations/Operation'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { SimplePatchOperationHandler } from '../../../../src/ldp/operations/SimplePatchOperationHandler'; +import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimplePatchOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts b/test/unit/ldp/operations/SimplePostOperationHandler.test.ts index 6af26f531e..40492ee873 100644 --- a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimplePostOperationHandler.test.ts @@ -1,7 +1,7 @@ import { Operation } from '../../../../src/ldp/operations/Operation'; +import { SimplePostOperationHandler } from '../../../../src/ldp/operations/SimplePostOperationHandler'; import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { ResourceStore } from '../../../../src/storage/ResourceStore'; -import { SimplePostOperationHandler } from '../../../../src/ldp/operations/SimplePostOperationHandler'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimplePostOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/SimplePutOperationHandler.test.ts b/test/unit/ldp/operations/SimplePutOperationHandler.test.ts index 2ddbf59a5f..6164544447 100644 --- a/test/unit/ldp/operations/SimplePutOperationHandler.test.ts +++ b/test/unit/ldp/operations/SimplePutOperationHandler.test.ts @@ -1,6 +1,6 @@ import { Operation } from '../../../../src/ldp/operations/Operation'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { SimplePutOperationHandler } from '../../../../src/ldp/operations/SimplePutOperationHandler'; +import { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimplePutOperationHandler', (): void => { diff --git a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts index 6a509bb000..0380a959fa 100644 --- a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts +++ b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts @@ -1,5 +1,5 @@ -import { BasePermissionsExtractor } from '../../../../src/ldp/permissions/BasePermissionsExtractor'; import { Operation } from '../../../../src/ldp/operations/Operation'; +import { BasePermissionsExtractor } from '../../../../src/ldp/permissions/BasePermissionsExtractor'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A BasePermissionsExtractor', (): void => { diff --git a/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts b/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts index 3a37ddd90b..67b7f8e02c 100644 --- a/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts +++ b/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts @@ -1,7 +1,7 @@ import { Factory } from 'sparqlalgebrajs'; +import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; import { Operation } from '../../../../src/ldp/operations/Operation'; import { SparqlPatchPermissionsExtractor } from '../../../../src/ldp/permissions/SparqlPatchPermissionsExtractor'; -import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SparqlPatchPermissionsExtractor', (): void => { diff --git a/test/unit/server/ExpressHttpServer.test.ts b/test/unit/server/ExpressHttpServer.test.ts index d84f7eccca..ee10f6fa5e 100644 --- a/test/unit/server/ExpressHttpServer.test.ts +++ b/test/unit/server/ExpressHttpServer.test.ts @@ -1,9 +1,9 @@ +import { Server } from 'http'; +import request from 'supertest'; import { ExpressHttpServer } from '../../../src/server/ExpressHttpServer'; import { HttpHandler } from '../../../src/server/HttpHandler'; import { HttpRequest } from '../../../src/server/HttpRequest'; import { HttpResponse } from '../../../src/server/HttpResponse'; -import request from 'supertest'; -import { Server } from 'http'; const handle = async(input: { request: HttpRequest; response: HttpResponse }): Promise => { input.response.writeHead(200); diff --git a/test/unit/storage/FileResourceStore.test.ts b/test/unit/storage/FileResourceStore.test.ts index db1b380ed9..41adab8e86 100644 --- a/test/unit/storage/FileResourceStore.test.ts +++ b/test/unit/storage/FileResourceStore.test.ts @@ -1,23 +1,23 @@ +import fs, { promises as fsPromises, Stats, WriteStream } from 'fs'; +import { posix } from 'path'; +import { Readable } from 'stream'; +import { literal, namedNode, quad as quadRDF, triple } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; -import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation'; -import { ConflictHttpError } from '../../../src/util/errors/ConflictHttpError'; import { DataFactory } from 'n3'; +import streamifyArray from 'streamify-array'; +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; +import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation'; +import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; import { FileResourceStore } from '../../../src/storage/FileResourceStore'; -import { InteractionController } from '../../../src/util/InteractionController'; -import { MetadataController } from '../../../src/util/MetadataController'; +import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../src/util/ContentTypes'; +import { ConflictHttpError } from '../../../src/util/errors/ConflictHttpError'; import { MethodNotAllowedHttpError } from '../../../src/util/errors/MethodNotAllowedHttpError'; import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; -import { posix } from 'path'; -import { Readable } from 'stream'; -import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; -import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; -import streamifyArray from 'streamify-array'; import { UnsupportedMediaTypeHttpError } from '../../../src/util/errors/UnsupportedMediaTypeHttpError'; -import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../src/util/ContentTypes'; -import fs, { promises as fsPromises, Stats, WriteStream } from 'fs'; -import { LDP, RDF, STAT, TERMS, XML } from '../../../src/util/Prefixes'; +import { InteractionController } from '../../../src/util/InteractionController'; import { LINK_TYPE_LDP_BC, LINK_TYPE_LDPR } from '../../../src/util/LinkTypes'; -import { literal, namedNode, quad as quadRDF, triple } from '@rdfjs/data-model'; +import { MetadataController } from '../../../src/util/MetadataController'; +import { LDP, RDF, STAT, TERMS, XML } from '../../../src/util/Prefixes'; const { join: joinPath } = posix; diff --git a/test/unit/storage/LockingResourceStore.test.ts b/test/unit/storage/LockingResourceStore.test.ts index d6fe6d73d4..bde1af7e84 100644 --- a/test/unit/storage/LockingResourceStore.test.ts +++ b/test/unit/storage/LockingResourceStore.test.ts @@ -1,11 +1,11 @@ import { EventEmitter } from 'events'; -import { Lock } from '../../../src/storage/Lock'; -import { LockingResourceStore } from '../../../src/storage/LockingResourceStore'; +import streamifyArray from 'streamify-array'; import { Patch } from '../../../src/ldp/http/Patch'; import { Representation } from '../../../src/ldp/representation/Representation'; +import { Lock } from '../../../src/storage/Lock'; +import { LockingResourceStore } from '../../../src/storage/LockingResourceStore'; import { ResourceLocker } from '../../../src/storage/ResourceLocker'; import { ResourceStore } from '../../../src/storage/ResourceStore'; -import streamifyArray from 'streamify-array'; describe('A LockingResourceStore', (): void => { let store: LockingResourceStore; diff --git a/test/unit/storage/PassthroughStore.test.ts b/test/unit/storage/PassthroughStore.test.ts index c43974f6ca..6e3aee666e 100644 --- a/test/unit/storage/PassthroughStore.test.ts +++ b/test/unit/storage/PassthroughStore.test.ts @@ -1,6 +1,6 @@ -import { PassthroughStore } from '../../../src/storage/PassthroughStore'; import { Patch } from '../../../src/ldp/http/Patch'; import { Representation } from '../../../src/ldp/representation/Representation'; +import { PassthroughStore } from '../../../src/storage/PassthroughStore'; import { ResourceStore } from '../../../src/storage/ResourceStore'; describe('A PassthroughStore', (): void => { diff --git a/test/unit/storage/SimpleResourceStore.test.ts b/test/unit/storage/SimpleResourceStore.test.ts index 546337d7b7..dd352a83f1 100644 --- a/test/unit/storage/SimpleResourceStore.test.ts +++ b/test/unit/storage/SimpleResourceStore.test.ts @@ -1,12 +1,12 @@ +import { Readable } from 'stream'; import arrayifyStream from 'arrayify-stream'; +import streamifyArray from 'streamify-array'; +import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation'; -import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes'; -import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; -import { Readable } from 'stream'; import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; -import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; import { SimpleResourceStore } from '../../../src/storage/SimpleResourceStore'; -import streamifyArray from 'streamify-array'; +import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes'; +import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; const base = 'http://test.com/'; diff --git a/test/unit/storage/conversion/QuadToTurtleConverter.test.ts b/test/unit/storage/conversion/QuadToTurtleConverter.test.ts index 7f2677a928..bc7282317c 100644 --- a/test/unit/storage/conversion/QuadToTurtleConverter.test.ts +++ b/test/unit/storage/conversion/QuadToTurtleConverter.test.ts @@ -1,12 +1,12 @@ -import arrayifyStream from 'arrayify-stream'; -import { QuadToTurtleConverter } from '../../../../src/storage/conversion/QuadToTurtleConverter'; import { Readable } from 'stream'; +import { namedNode, triple } from '@rdfjs/data-model'; +import arrayifyStream from 'arrayify-stream'; +import streamifyArray from 'streamify-array'; import { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; -import streamifyArray from 'streamify-array'; +import { QuadToTurtleConverter } from '../../../../src/storage/conversion/QuadToTurtleConverter'; import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; -import { namedNode, triple } from '@rdfjs/data-model'; describe('A QuadToTurtleConverter', (): void => { const converter = new QuadToTurtleConverter(); diff --git a/test/unit/storage/conversion/TurtleToQuadConverter.test.ts b/test/unit/storage/conversion/TurtleToQuadConverter.test.ts index af92ed4491..82c26b2886 100644 --- a/test/unit/storage/conversion/TurtleToQuadConverter.test.ts +++ b/test/unit/storage/conversion/TurtleToQuadConverter.test.ts @@ -1,13 +1,13 @@ -import arrayifyStream from 'arrayify-stream'; import { Readable } from 'stream'; +import { namedNode, triple } from '@rdfjs/data-model'; +import arrayifyStream from 'arrayify-stream'; +import streamifyArray from 'streamify-array'; import { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; -import streamifyArray from 'streamify-array'; import { TurtleToQuadConverter } from '../../../../src/storage/conversion/TurtleToQuadConverter'; -import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes'; -import { namedNode, triple } from '@rdfjs/data-model'; +import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A TurtleToQuadConverter', (): void => { const converter = new TurtleToQuadConverter(); diff --git a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts b/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts index e7bab4a5c0..9f8f84557b 100644 --- a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts +++ b/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts @@ -1,15 +1,15 @@ +import { namedNode, quad } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; -import { Lock } from '../../../../src/storage/Lock'; import { Quad } from 'rdf-js'; +import { translate } from 'sparqlalgebrajs'; +import streamifyArray from 'streamify-array'; +import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; +import { Lock } from '../../../../src/storage/Lock'; +import { SimpleSparqlUpdatePatchHandler } from '../../../../src/storage/patch/SimpleSparqlUpdatePatchHandler'; import { ResourceLocker } from '../../../../src/storage/ResourceLocker'; import { ResourceStore } from '../../../../src/storage/ResourceStore'; -import { SimpleSparqlUpdatePatchHandler } from '../../../../src/storage/patch/SimpleSparqlUpdatePatchHandler'; -import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; -import streamifyArray from 'streamify-array'; -import { translate } from 'sparqlalgebrajs'; -import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes'; -import { namedNode, quad } from '@rdfjs/data-model'; +import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A SimpleSparqlUpdatePatchHandler', (): void => { let handler: SimpleSparqlUpdatePatchHandler; diff --git a/test/util/Util.ts b/test/util/Util.ts index a3ad93d1ff..bf3726abad 100644 --- a/test/util/Util.ts +++ b/test/util/Util.ts @@ -1,9 +1,9 @@ import { EventEmitter } from 'events'; -import { HttpHandler } from '../../src/server/HttpHandler'; -import { HttpRequest } from '../../src/server/HttpRequest'; import { IncomingHttpHeaders } from 'http'; -import streamifyArray from 'streamify-array'; import { createResponse, MockResponse } from 'node-mocks-http'; +import streamifyArray from 'streamify-array'; +import { HttpHandler } from '../../src/server/HttpHandler'; +import { HttpRequest } from '../../src/server/HttpRequest'; export const call = async(handler: HttpHandler, requestUrl: URL, method: string, headers: IncomingHttpHeaders, data: string[]): Promise> => { From 86d5f367d52b769b563a8ad6ea1a02274f9ec5ab Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Thu, 27 Aug 2020 14:59:42 +0200 Subject: [PATCH 3/5] feat: Support link and slug headers in SimpleBodyParser --- src/ldp/http/SimpleBodyParser.ts | 50 ++++++++++++++++----- test/integration/RequestParser.test.ts | 1 - test/unit/ldp/http/SimpleBodyParser.test.ts | 49 ++++++++++++++++++-- 3 files changed, 86 insertions(+), 14 deletions(-) diff --git a/src/ldp/http/SimpleBodyParser.ts b/src/ldp/http/SimpleBodyParser.ts index a62ad094df..8c7b2ad3c1 100644 --- a/src/ldp/http/SimpleBodyParser.ts +++ b/src/ldp/http/SimpleBodyParser.ts @@ -1,5 +1,6 @@ import { HttpRequest } from '../../server/HttpRequest'; import { DATA_TYPE_BINARY } from '../../util/ContentTypes'; +import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { BinaryRepresentation } from '../representation/BinaryRepresentation'; import { RepresentationMetadata } from '../representation/RepresentationMetadata'; import { BodyParser } from './BodyParser'; @@ -17,24 +18,53 @@ export class SimpleBodyParser extends BodyParser { // Note that the only reason this is a union is in case the body is empty. // If this check gets moved away from the BodyParsers this union could be removed public async handle(input: HttpRequest): Promise { - const contentType = input.headers['content-type']; - - if (!contentType) { + if (!input.headers['content-type']) { return; } - const mediaType = contentType.split(';')[0]; + return { + dataType: DATA_TYPE_BINARY, + data: input, + metadata: this.parseMetadata(input), + }; + } + + private parseMetadata(input: HttpRequest): RepresentationMetadata { + const mediaType = input.headers['content-type']!.split(';')[0]; const metadata: RepresentationMetadata = { raw: [], - profiles: [], contentType: mediaType, }; - return { - dataType: DATA_TYPE_BINARY, - data: input, - metadata, - }; + const { link, slug } = input.headers; + + if (slug) { + if (Array.isArray(slug)) { + throw new UnsupportedHttpError('At most 1 slug header is allowed.'); + } + metadata.slug = slug; + } + + // There are similarities here to Accept header parsing so that library should become more generic probably + if (link) { + metadata.linkRel = {}; + const linkArray = Array.isArray(link) ? link : [ link ]; + const parsedLinks = linkArray.map((entry): { url: string; rel: string } => { + const [ , url, rest ] = /^<([^>]*)>(.*)$/u.exec(entry) ?? []; + const [ , rel ] = /^ *; *rel="(.*)"$/u.exec(rest) ?? []; + return { url, rel }; + }); + parsedLinks.forEach((entry): void => { + if (entry.rel) { + if (!metadata.linkRel![entry.rel]) { + metadata.linkRel![entry.rel] = new Set(); + } + metadata.linkRel![entry.rel].add(entry.url); + } + }); + } + + return metadata; } } diff --git a/test/integration/RequestParser.test.ts b/test/integration/RequestParser.test.ts index 76fb6392d1..86867adc1d 100644 --- a/test/integration/RequestParser.test.ts +++ b/test/integration/RequestParser.test.ts @@ -38,7 +38,6 @@ describe('A SimpleRequestParser with simple input parsers', (): void => { dataType: DATA_TYPE_BINARY, metadata: { contentType: 'text/turtle', - profiles: [], raw: [], }, }, diff --git a/test/unit/ldp/http/SimpleBodyParser.test.ts b/test/unit/ldp/http/SimpleBodyParser.test.ts index 8f91f7ac77..e70ee6b233 100644 --- a/test/unit/ldp/http/SimpleBodyParser.test.ts +++ b/test/unit/ldp/http/SimpleBodyParser.test.ts @@ -1,9 +1,9 @@ -import { Readable } from 'stream'; import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; import { SimpleBodyParser } from '../../../../src/ldp/http/SimpleBodyParser'; import { HttpRequest } from '../../../../src/server/HttpRequest'; import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes'; +import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import 'jest-rdf'; describe('A SimpleBodyparser', (): void => { @@ -22,11 +22,10 @@ describe('A SimpleBodyparser', (): void => { input.headers = { 'content-type': 'text/turtle' }; const result = (await bodyParser.handle(input))!; expect(result).toEqual({ - data: expect.any(Readable), + data: input, dataType: DATA_TYPE_BINARY, metadata: { contentType: 'text/turtle', - profiles: [], raw: [], }, }); @@ -34,4 +33,48 @@ describe('A SimpleBodyparser', (): void => { [ ' .' ], ); }); + + it('adds the slug header to the metadata.', async(): Promise => { + const input = {} as HttpRequest; + input.headers = { 'content-type': 'text/turtle', slug: 'slugText' }; + const result = (await bodyParser.handle(input))!; + expect(result.metadata).toEqual({ + contentType: 'text/turtle', + raw: [], + slug: 'slugText', + }); + }); + + it('errors if there are multiple slugs.', async(): Promise => { + const input = {} as HttpRequest; + input.headers = { 'content-type': 'text/turtle', slug: [ 'slugTextA', 'slugTextB' ]}; + await expect(bodyParser.handle(input)).rejects.toThrow(UnsupportedHttpError); + }); + + it('adds the link headers to the metadata.', async(): Promise => { + const input = {} as HttpRequest; + input.headers = { 'content-type': 'text/turtle', link: '; rel="type"' }; + const result = (await bodyParser.handle(input))!; + expect(result.metadata).toEqual({ + contentType: 'text/turtle', + raw: [], + linkRel: { type: new Set([ 'http://www.w3.org/ns/ldp#Container' ]) }, + }); + }); + + it('supports multiple link headers.', async(): Promise => { + const input = {} as HttpRequest; + input.headers = { 'content-type': 'text/turtle', + link: [ '; rel="type"', + '; rel="type"', + '', + 'badLink', + ]}; + const result = (await bodyParser.handle(input))!; + expect(result.metadata).toEqual({ + contentType: 'text/turtle', + raw: [], + linkRel: { type: new Set([ 'http://www.w3.org/ns/ldp#Container', 'http://www.w3.org/ns/ldp#Resource' ]) }, + }); + }); }); From 075295b828af59ba12e3096c6126aee59da12967 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 28 Aug 2020 10:27:44 +0200 Subject: [PATCH 4/5] Enable dependency updating via Renovate --- renovate.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..d282bab0e7 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "github>rubensworks/renovate-presets:js" + ] +} From 267b3dc8cbc3c3f94e88445b46caa1af0579845a Mon Sep 17 00:00:00 2001 From: iesmessa Date: Fri, 28 Aug 2020 15:27:41 +0200 Subject: [PATCH 5/5] Merge branch master from upstream into sparql-resource-store --- bin/server.ts | 4 ++-- src/storage/SimpleResourceStore.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/server.ts b/bin/server.ts index 5b625fd570..3c75986f33 100644 --- a/bin/server.ts +++ b/bin/server.ts @@ -1,6 +1,4 @@ #!/usr/bin/env node -import { InteractionController } from '../src/util/InteractionController'; -import { ResourceStoreController } from '../src/util/ResourceStoreController'; import yargs from 'yargs'; import { AcceptPreferenceParser, @@ -35,6 +33,8 @@ import { TurtleToQuadConverter, UrlContainerManager, } from '..'; +import { InteractionController } from '../src/util/InteractionController'; +import { ResourceStoreController } from '../src/util/ResourceStoreController'; const { argv } = yargs .usage('node ./bin/server.js [args]') diff --git a/src/storage/SimpleResourceStore.ts b/src/storage/SimpleResourceStore.ts index 363257f027..d89d1f69e1 100644 --- a/src/storage/SimpleResourceStore.ts +++ b/src/storage/SimpleResourceStore.ts @@ -1,12 +1,12 @@ import arrayifyStream from 'arrayify-stream'; +import streamifyArray from 'streamify-array'; import { Representation } from '../ldp/representation/Representation'; import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { DATA_TYPE_BINARY } from '../util/ContentTypes'; import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; +import { ResourceStoreController } from '../util/ResourceStoreController'; import { ensureTrailingSlash } from '../util/Util'; import { ResourceStore } from './ResourceStore'; -import { ResourceStoreController } from '../util/ResourceStoreController'; -import streamifyArray from 'streamify-array'; /** * Resource store storing its data in an in-memory map. @@ -18,7 +18,6 @@ export class SimpleResourceStore implements ResourceStore { private readonly resourceStoreController: ResourceStoreController; /** -<<<<<<< HEAD * @param resourceStoreController - Instance of ResourceStoreController to use. */ public constructor(resourceStoreController: ResourceStoreController) {