Merge pull request #5 from h3poteto/types

Update definitely types for entities
This commit is contained in:
AkiraFukushima 2018-07-16 10:24:45 +09:00 committed by GitHub
commit ec6aa6417e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 769 additions and 20 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
node_modules
lib
example/typescript/dist

View file

@ -58,7 +58,7 @@ Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL)
## Get timeline
```typescript
import Mastodon from 'megalodon'
import Mastodon, { Status } from 'megalodon'
const BASE_URL: string = 'https://friends.nico'
@ -69,14 +69,16 @@ const client = new Mastodon(
BASE_URL + '/api/v1'
)
client.get('/timelines/home')
.then(resp => console.log(resp))
client.get<[Status]>('/timelines/home')
.then((resp: Status) => {
console.log(resp)
})
```
## Post toot
```typescript
import Mastodon from 'megalodon'
import Mastodon, { Status } from 'megalodon'
const BASE_URL: string = 'https://friends.nico'
@ -89,10 +91,10 @@ const client = new Mastodon(
BASE_URL + '/api/v1'
)
client.post('/statuses', {
client.post<Status>('/statuses', {
status: toot
})
.then(res => {
.then((res: Status) => {
console.log(res)
})

View file

@ -1,5 +1,5 @@
import * as readline from 'readline'
import Mastodon from '../../src/mastodon'
import Mastodon from 'megalodon'
const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
@ -7,7 +7,7 @@ const rl: readline.ReadLine = readline.createInterface({
})
const SCOPES: string = 'read write follow'
const BASE_URL: string = 'https://friends.nico'
const BASE_URL: string = 'https://mastodon.social'
let clientId: string
let clientSecret: string

660
example/typescript/package-lock.json generated Normal file
View file

@ -0,0 +1,660 @@
{
"name": "example",
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"megalodon": {
"version": "file:../..",
"requires": {
"@types/oauth": "0.9.0",
"@types/request": "2.47.0",
"axios": "0.18.0",
"oauth": "0.9.15",
"request": "2.87.0",
"typescript": "2.9.1"
},
"dependencies": {
"@types/caseless": {
"version": "0.12.1",
"bundled": true
},
"@types/form-data": {
"version": "2.2.1",
"bundled": true,
"requires": {
"@types/node": "10.3.2"
}
},
"@types/node": {
"version": "10.3.2",
"bundled": true
},
"@types/oauth": {
"version": "0.9.0",
"bundled": true,
"requires": {
"@types/node": "10.3.2"
}
},
"@types/request": {
"version": "2.47.0",
"bundled": true,
"requires": {
"@types/caseless": "0.12.1",
"@types/form-data": "2.2.1",
"@types/node": "10.3.2",
"@types/tough-cookie": "2.3.3"
}
},
"@types/tough-cookie": {
"version": "2.3.3",
"bundled": true
},
"ajv": {
"version": "5.5.2",
"bundled": true,
"requires": {
"co": "4.6.0",
"fast-deep-equal": "1.1.0",
"fast-json-stable-stringify": "2.0.0",
"json-schema-traverse": "0.3.1"
}
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
},
"ansi-styles": {
"version": "2.2.1",
"bundled": true
},
"argparse": {
"version": "1.0.10",
"bundled": true,
"requires": {
"sprintf-js": "1.0.3"
}
},
"asn1": {
"version": "0.2.3",
"bundled": true
},
"assert-plus": {
"version": "1.0.0",
"bundled": true
},
"asynckit": {
"version": "0.4.0",
"bundled": true
},
"aws-sign2": {
"version": "0.7.0",
"bundled": true
},
"aws4": {
"version": "1.7.0",
"bundled": true
},
"axios": {
"version": "0.18.0",
"bundled": true,
"requires": {
"follow-redirects": "1.5.0",
"is-buffer": "1.1.6"
}
},
"babel-code-frame": {
"version": "6.26.0",
"bundled": true,
"requires": {
"chalk": "1.1.3",
"esutils": "2.0.2",
"js-tokens": "3.0.2"
},
"dependencies": {
"chalk": {
"version": "1.1.3",
"bundled": true,
"requires": {
"ansi-styles": "2.2.1",
"escape-string-regexp": "1.0.5",
"has-ansi": "2.0.0",
"strip-ansi": "3.0.1",
"supports-color": "2.0.0"
}
}
}
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
},
"bcrypt-pbkdf": {
"version": "1.0.1",
"bundled": true,
"optional": true,
"requires": {
"tweetnacl": "0.14.5"
}
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"requires": {
"balanced-match": "1.0.0",
"concat-map": "0.0.1"
}
},
"builtin-modules": {
"version": "1.1.1",
"bundled": true
},
"caseless": {
"version": "0.12.0",
"bundled": true
},
"chalk": {
"version": "2.4.1",
"bundled": true,
"requires": {
"ansi-styles": "3.2.1",
"escape-string-regexp": "1.0.5",
"supports-color": "5.4.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"bundled": true,
"requires": {
"color-convert": "1.9.1"
}
},
"supports-color": {
"version": "5.4.0",
"bundled": true,
"requires": {
"has-flag": "3.0.0"
}
}
}
},
"co": {
"version": "4.6.0",
"bundled": true
},
"color-convert": {
"version": "1.9.1",
"bundled": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"bundled": true
},
"combined-stream": {
"version": "1.0.6",
"bundled": true,
"requires": {
"delayed-stream": "1.0.0"
}
},
"commander": {
"version": "2.15.1",
"bundled": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true
},
"dashdash": {
"version": "1.14.1",
"bundled": true,
"requires": {
"assert-plus": "1.0.0"
}
},
"debug": {
"version": "3.1.0",
"bundled": true,
"requires": {
"ms": "2.0.0"
}
},
"delayed-stream": {
"version": "1.0.0",
"bundled": true
},
"diff": {
"version": "3.5.0",
"bundled": true
},
"doctrine": {
"version": "0.7.2",
"bundled": true,
"requires": {
"esutils": "1.1.6",
"isarray": "0.0.1"
},
"dependencies": {
"esutils": {
"version": "1.1.6",
"bundled": true
}
}
},
"ecc-jsbn": {
"version": "0.1.1",
"bundled": true,
"optional": true,
"requires": {
"jsbn": "0.1.1"
}
},
"escape-string-regexp": {
"version": "1.0.5",
"bundled": true
},
"esprima": {
"version": "4.0.0",
"bundled": true
},
"esutils": {
"version": "2.0.2",
"bundled": true
},
"extend": {
"version": "3.0.1",
"bundled": true
},
"extsprintf": {
"version": "1.3.0",
"bundled": true
},
"fast-deep-equal": {
"version": "1.1.0",
"bundled": true
},
"fast-json-stable-stringify": {
"version": "2.0.0",
"bundled": true
},
"follow-redirects": {
"version": "1.5.0",
"bundled": true,
"requires": {
"debug": "3.1.0"
}
},
"forever-agent": {
"version": "0.6.1",
"bundled": true
},
"form-data": {
"version": "2.3.2",
"bundled": true,
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.6",
"mime-types": "2.1.18"
}
},
"fs.realpath": {
"version": "1.0.0",
"bundled": true
},
"getpass": {
"version": "0.1.7",
"bundled": true,
"requires": {
"assert-plus": "1.0.0"
}
},
"glob": {
"version": "7.1.2",
"bundled": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"har-schema": {
"version": "2.0.0",
"bundled": true
},
"har-validator": {
"version": "5.0.3",
"bundled": true,
"requires": {
"ajv": "5.5.2",
"har-schema": "2.0.0"
}
},
"has-ansi": {
"version": "2.0.0",
"bundled": true,
"requires": {
"ansi-regex": "2.1.1"
}
},
"has-flag": {
"version": "3.0.0",
"bundled": true
},
"http-signature": {
"version": "1.2.0",
"bundled": true,
"requires": {
"assert-plus": "1.0.0",
"jsprim": "1.4.1",
"sshpk": "1.14.2"
}
},
"inflight": {
"version": "1.0.6",
"bundled": true,
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"bundled": true
},
"is-buffer": {
"version": "1.1.6",
"bundled": true
},
"is-typedarray": {
"version": "1.0.0",
"bundled": true
},
"isarray": {
"version": "0.0.1",
"bundled": true
},
"isstream": {
"version": "0.1.2",
"bundled": true
},
"js-tokens": {
"version": "3.0.2",
"bundled": true
},
"js-yaml": {
"version": "3.12.0",
"bundled": true,
"requires": {
"argparse": "1.0.10",
"esprima": "4.0.0"
}
},
"jsbn": {
"version": "0.1.1",
"bundled": true,
"optional": true
},
"json-schema": {
"version": "0.2.3",
"bundled": true
},
"json-schema-traverse": {
"version": "0.3.1",
"bundled": true
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true
},
"jsprim": {
"version": "1.4.1",
"bundled": true,
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.3.0",
"json-schema": "0.2.3",
"verror": "1.10.0"
}
},
"mime-db": {
"version": "1.33.0",
"bundled": true
},
"mime-types": {
"version": "2.1.18",
"bundled": true,
"requires": {
"mime-db": "1.33.0"
}
},
"minimatch": {
"version": "3.0.4",
"bundled": true,
"requires": {
"brace-expansion": "1.1.11"
}
},
"ms": {
"version": "2.0.0",
"bundled": true
},
"oauth": {
"version": "0.9.15",
"bundled": true
},
"oauth-sign": {
"version": "0.8.2",
"bundled": true
},
"once": {
"version": "1.4.0",
"bundled": true,
"requires": {
"wrappy": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"bundled": true
},
"path-parse": {
"version": "1.0.5",
"bundled": true
},
"performance-now": {
"version": "2.1.0",
"bundled": true
},
"punycode": {
"version": "1.4.1",
"bundled": true
},
"qs": {
"version": "6.5.2",
"bundled": true
},
"request": {
"version": "2.87.0",
"bundled": true,
"requires": {
"aws-sign2": "0.7.0",
"aws4": "1.7.0",
"caseless": "0.12.0",
"combined-stream": "1.0.6",
"extend": "3.0.1",
"forever-agent": "0.6.1",
"form-data": "2.3.2",
"har-validator": "5.0.3",
"http-signature": "1.2.0",
"is-typedarray": "1.0.0",
"isstream": "0.1.2",
"json-stringify-safe": "5.0.1",
"mime-types": "2.1.18",
"oauth-sign": "0.8.2",
"performance-now": "2.1.0",
"qs": "6.5.2",
"safe-buffer": "5.1.2",
"tough-cookie": "2.3.4",
"tunnel-agent": "0.6.0",
"uuid": "3.2.1"
}
},
"resolve": {
"version": "1.7.1",
"bundled": true,
"requires": {
"path-parse": "1.0.5"
}
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
"bundled": true
},
"semver": {
"version": "5.5.0",
"bundled": true
},
"sprintf-js": {
"version": "1.0.3",
"bundled": true
},
"sshpk": {
"version": "1.14.2",
"bundled": true,
"requires": {
"asn1": "0.2.3",
"assert-plus": "1.0.0",
"bcrypt-pbkdf": "1.0.1",
"dashdash": "1.14.1",
"ecc-jsbn": "0.1.1",
"getpass": "0.1.7",
"jsbn": "0.1.1",
"safer-buffer": "2.1.2",
"tweetnacl": "0.14.5"
}
},
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"requires": {
"ansi-regex": "2.1.1"
}
},
"supports-color": {
"version": "2.0.0",
"bundled": true
},
"tough-cookie": {
"version": "2.3.4",
"bundled": true,
"requires": {
"punycode": "1.4.1"
}
},
"tslib": {
"version": "1.9.2",
"bundled": true
},
"tslint": {
"version": "5.10.0",
"bundled": true,
"requires": {
"babel-code-frame": "6.26.0",
"builtin-modules": "1.1.1",
"chalk": "2.4.1",
"commander": "2.15.1",
"diff": "3.5.0",
"glob": "7.1.2",
"js-yaml": "3.12.0",
"minimatch": "3.0.4",
"resolve": "1.7.1",
"semver": "5.5.0",
"tslib": "1.9.2",
"tsutils": "2.27.1"
}
},
"tslint-config-standard": {
"version": "7.0.0",
"bundled": true,
"requires": {
"tslint-eslint-rules": "4.1.1"
}
},
"tslint-eslint-rules": {
"version": "4.1.1",
"bundled": true,
"requires": {
"doctrine": "0.7.2",
"tslib": "1.9.2",
"tsutils": "1.9.1"
},
"dependencies": {
"tsutils": {
"version": "1.9.1",
"bundled": true
}
}
},
"tsutils": {
"version": "2.27.1",
"bundled": true,
"requires": {
"tslib": "1.9.2"
}
},
"tunnel-agent": {
"version": "0.6.0",
"bundled": true,
"requires": {
"safe-buffer": "5.1.2"
}
},
"tweetnacl": {
"version": "0.14.5",
"bundled": true,
"optional": true
},
"typescript": {
"version": "2.9.1",
"bundled": true
},
"uuid": {
"version": "3.2.1",
"bundled": true
},
"verror": {
"version": "1.10.0",
"bundled": true,
"requires": {
"assert-plus": "1.0.0",
"core-util-is": "1.0.2",
"extsprintf": "1.3.0"
}
},
"wrappy": {
"version": "1.0.2",
"bundled": true
}
}
},
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w=="
}
}
}

View file

@ -0,0 +1,12 @@
{
"name": "example",
"scripts": {
"build": "tsc -p ./"
},
"author": "h3poteto",
"license": "MIT",
"dependencies": {
"typescript": "^2.9.2",
"megalodon": "file:../../"
}
}

View file

@ -1,6 +1,6 @@
import Mastodon from '../../src/mastodon'
import Mastodon from 'megalodon'
const BASE_URL: string = 'https://friends.nico'
const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...'

View file

@ -1,6 +1,6 @@
import Mastodon from '../../src/mastodon'
import Mastodon, { Status } from 'megalodon'
const BASE_URL: string = 'https://friends.nico'
const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...'
@ -9,5 +9,7 @@ const client = new Mastodon(
BASE_URL + '/api/v1'
)
client.get('/timelines/home')
.then(resp => console.log(resp))
client.get<[Status]>('/timelines/home')
.then((resp: [Status]) => {
console.log(resp)
})

View file

@ -1,12 +1,12 @@
import * as readline from 'readline'
import Mastodon from '../../src/mastodon'
import Mastodon, { Status } from 'megalodon'
const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const BASE_URL: string = 'https://friends.nico'
const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...'
@ -16,10 +16,10 @@ const client = new Mastodon(
)
new Promise(resolve => {
rl.question('Toot: ', status => {
client.post('/statuses', {
client.post<Status>('/statuses', {
status: status
})
.then(res => {
.then((res: Status) => {
console.log(res)
rl.close()
resolve(res)

View file

@ -0,0 +1,60 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es6"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["./"]
}

View file

@ -2,8 +2,8 @@
"name": "megalodon",
"version": "0.1.1",
"description": "Mastodon API client for node.js",
"main": "./lib/mastodon.js",
"typings": "./lib/mastodon.d.ts",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"scripts": {
"build": "tsc -p ./",
"lint": "tslint './src/*.ts'",

11
src/index.ts Normal file
View file

@ -0,0 +1,11 @@
import Mastodon from './mastodon'
import Application from './entities/application'
import Mention from './entities/mention'
import Notification from './entities/notification'
import Status from './entities/status'
import Tag from './entities/tag'
export { Application, Mention, Notification, Status, Tag }
export default Mastodon