mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Add activestorage
This commit is contained in:
28
types/activestorage/activestorage-tests.ts
Normal file
28
types/activestorage/activestorage-tests.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as ActiveStorage from 'activestorage';
|
||||
|
||||
ActiveStorage.start();
|
||||
|
||||
const delegate: ActiveStorage.DirectUploadDelegate = {
|
||||
directUploadWillCreateBlobWithXHR(xhr) {
|
||||
console.log(xhr.status);
|
||||
},
|
||||
|
||||
directUploadWillStoreFileWithXHR(xhr) {
|
||||
console.log(xhr.status);
|
||||
},
|
||||
};
|
||||
|
||||
const d = new ActiveStorage.DirectUpload(
|
||||
new File([], 'blank.txt'),
|
||||
'/rails/active_storage/direct_uploads',
|
||||
delegate
|
||||
);
|
||||
|
||||
d.create((error, blob) => {
|
||||
if (error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
const { byte_size, checksum, content_type, filename, signed_id } = blob;
|
||||
console.log({ byte_size, checksum, content_type, filename, signed_id });
|
||||
}
|
||||
});
|
||||
33
types/activestorage/index.d.ts
vendored
Normal file
33
types/activestorage/index.d.ts
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// Type definitions for ActiveStorage 5.2
|
||||
// Project: https://github.com/rails/rails/tree/master/activestorage/app/javascipt
|
||||
// Definitions by: Cameron Bothner <https://github.com/cbothner>
|
||||
// Definitions: https://github.com/cbothner/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
export as namespace ActiveStorage
|
||||
|
||||
export function start(): void;
|
||||
|
||||
export class DirectUpload {
|
||||
id: number;
|
||||
file: File;
|
||||
url: string;
|
||||
|
||||
constructor(file: File, url: string, delegate: DirectUploadDelegate)
|
||||
|
||||
create(callback: (error: Error, blob: Blob) => void): void;
|
||||
}
|
||||
|
||||
export interface DirectUploadDelegate {
|
||||
directUploadWillCreateBlobWithXHR?: (xhr: XMLHttpRequest) => void;
|
||||
|
||||
directUploadWillStoreFileWithXHR?: (xhr: XMLHttpRequest) => void;
|
||||
}
|
||||
|
||||
export interface Blob {
|
||||
byte_size: number;
|
||||
checksum: string;
|
||||
content_type: string;
|
||||
filename: string;
|
||||
signed_id: string;
|
||||
}
|
||||
16
types/activestorage/tsconfig.json
Normal file
16
types/activestorage/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "activestorage-tests.ts"]
|
||||
}
|
||||
1
types/activestorage/tslint.json
Normal file
1
types/activestorage/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user