refactor: support inrupt coding standards

This commit is contained in:
Joachim Van Herwegen
2020-05-20 17:27:54 +02:00
parent 5def53180c
commit f8e136cadb
25 changed files with 722 additions and 604 deletions

View File

@@ -0,0 +1,8 @@
import { Representation } from './Representation';
/**
* A representation containing binary data.
*/
export interface BinaryRepresentation extends Representation {
dataType: 'binary';
}

View File

@@ -0,0 +1,9 @@
import { Representation } from './Representation';
import { ResourceIdentifier } from './ResourceIdentifier';
export interface NamedRepresentation extends Representation {
/**
* The identifier of this representation.
*/
identifier?: ResourceIdentifier;
}

4
src/ldp/http/Patch.ts Normal file
View File

@@ -0,0 +1,4 @@
/**
* Represents the changes needed for a PATCH request.
*/
export interface Patch {}

View File

@@ -0,0 +1,8 @@
import { Representation } from './Representation';
/**
* A representation containing quads as data.
*/
export interface QuadRepresentation extends Representation {
dataType: 'quad';
}

View File

@@ -0,0 +1,20 @@
import { Readable } from 'stream';
import { RepresentationMetadata } from './RepresentationMetadata';
/**
* A representation of a resource.
*/
export interface Representation {
/**
* The corresponding metadata.
*/
metadata: RepresentationMetadata;
/**
* The raw data stream for this representation.
*/
data: Readable;
/**
* The data type of the contents in the data stream.
*/
dataType: string;
}

View File

@@ -0,0 +1,35 @@
/**
* Contains metadata relevant to a representation.
*/
import { Quad } from 'rdf-js';
export interface RepresentationMetadata {
/**
* All metadata triples of the resource.
*/
raw: Quad[];
/**
* The metadata profiles.
*/
profiles: string[];
/**
* Optional size of the representation.
*/
byteSize?: number;
/**
* Optional content type of the representation.
*/
contentType?: string;
/**
* Optional encoding of the representation.
*/
encoding?: string;
/**
* Optional language of the representation.
*/
language?: string;
/**
* Optional timestamp of the representation.
*/
dateTime?: Date;
}

View File

@@ -0,0 +1,4 @@
/**
* Contains the preferences of which kind of representation is requested.
*/
export interface RepresentationPreferences {}

View File

@@ -0,0 +1,4 @@
/**
* The unique identifier of a resource.
*/
export interface ResourceIdentifier {}

View File

@@ -0,0 +1,25 @@
import { Representation } from '../http/Representation';
import { RepresentationPreferences } from '../http/RepresentationPreferences';
import { ResourceIdentifier } from '../http/ResourceIdentifier';
/**
* A single REST operation.
*/
export interface Operation {
/**
* The HTTP method (GET/POST/PUT/PATCH/DELETE/etc.).
*/
method: string;
/**
* Identifier of the target.
*/
target: ResourceIdentifier;
/**
* Representation preferences of the response. Will be empty if there are none.
*/
preferences: RepresentationPreferences;
/**
* Optional representation of the body.
*/
body?: Representation;
}

View File

@@ -0,0 +1,21 @@
import { Operation } from './Operation';
/**
* Handler for a specific operation type.
*/
export interface OperationHandler {
/**
* Checks if the handler supports the given operation.
* @param operation - The input operation.
*
* @returns A promise resolving to a boolean indicating if this handler supports the operation.
*/
canHandle: (operation: Operation) => Promise<boolean>;
/**
* Handles the given operation.
* @param operation - The input operation.
*
* @returns A promise resolving when the operation is handled.
*/
handle: (operation: Operation) => Promise<void>;
}