Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ghost-storage-base] add module types #36751

Merged
merged 8 commits into from Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions types/ghost-storage-base/ghost-storage-base-tests.ts
@@ -0,0 +1,45 @@
import { StorageBase, Image, ReadOptions } from 'ghost-storage-base';
import { Request, Response, NextFunction } from 'express';

class MyCustomAdapter extends StorageBase {
constructor() {
super();
}

async exists(fileName: string, targetDir?: string) {
return true;
}

async save(image: Image, targetDir?: string) {
return 'string';
}

serve() {
return (req: Request, res: Response, next: NextFunction) => next();
}

async delete(fileName: string, targetDir?: string) {
return true;
}

async read(options: ReadOptions) {
return Buffer.from([]);
}
}

const image: Image = {
path: 'tmp/123456.jpg',
name: 'IMAGE.jpg',
type: 'image/jpeg',
};

const storage = new MyCustomAdapter();

storage.getTargetDir('/'); // $ExpectType string
storage.getUniqueFileName(image, '/target'); // $ExpectType string
storage.getSanitizedFileName('IMAGE.jpg'); // $ExpectType string

storage.exists('tmp/123456.jpg', '/'); // $ExpectType Promise<boolean>
storage.save(image, '/'); // $ExpectType Promise<string>
storage.serve(); // $ExpectType (req: Request, res: Response, next: NextFunction) => void
storage.delete('tmp/123456.jpg', '/'); // $ExpectType Promise<boolean>
31 changes: 31 additions & 0 deletions types/ghost-storage-base/index.d.ts
@@ -0,0 +1,31 @@
// Type definitions for ghost-storage-base 0.0
// Project: https://github.com/TryGhost/Ghost-Storage-Base
// Definitions by: Demian <https://github.com/thde>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

import { Handler } from 'express';

export interface Image {
path: string;
name: string;
type: string;
}

export interface ReadOptions {
path: string;
}

export abstract class StorageBase {
constructor();

abstract exists(fileName: string, targetDir?: string): Promise<boolean>;
abstract save(image: Image, targetDir?: string): Promise<string>;
abstract serve(): Handler;
abstract delete(fileName: string, targetDir?: string): Promise<boolean>;
abstract read(options?: ReadOptions): Promise<Buffer>;

getTargetDir(baseDir?: string): string;
getUniqueFileName(image: Image, targetDir: string): string;
getSanitizedFileName(fileName: string): string;
}
23 changes: 23 additions & 0 deletions types/ghost-storage-base/tsconfig.json
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ghost-storage-base-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/ghost-storage-base/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }