瀏覽代碼

futher setup and module skeleton

tags/v1.0.0-alpha.0
ojizero 1 年之前
父節點
當前提交
9c170c6452
沒有連結到貢獻者的電子郵件帳戶。
共有 19 個檔案被更改,包括 1977 行新增56 行删除
  1. 2
    49
      .gitignore
  2. 1
    0
      .npmignore
  3. 35
    0
      README.md
  4. 0
    3
      index.js
  5. 1736
    0
      package-lock.json
  6. 26
    4
      package.json
  7. 1
    0
      src/client.ts
  8. 57
    0
      src/index.ts
  9. 1
    0
      src/method.ts
  10. 1
    0
      src/resource.ts
  11. 5
    0
      test/client.spec.ts
  12. 3
    0
      test/index.spec.ts
  13. 3
    0
      test/method.spec.ts
  14. 4
    0
      test/mocha.opts
  15. 3
    0
      test/resource.spec.ts
  16. 9
    0
      test/setup.ts
  17. 6
    0
      test/typings/globals.d.ts
  18. 61
    0
      tsconfig.json
  19. 23
    0
      tsconfig.spec.json

+ 2
- 49
.gitignore 查看文件

@@ -1,8 +1,3 @@

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

### Node ###
# Logs
logs
*.log
@@ -25,24 +20,8 @@ coverage
# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm
@@ -56,31 +35,5 @@ typings/
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

#DynamoDB Local files
.dynamodb/

# End of https://www.gitignore.io/api/node
# Compiled code
lib

+ 1
- 0
.npmignore 查看文件

@@ -0,0 +1 @@
# TODO:

+ 35
- 0
README.md 查看文件

@@ -5,3 +5,38 @@
> HTTP API clients ... simplified.

</div>

## Installation

```
npm install --save @ojizero/portal
```

## Usage

Aimed to be used as a building block for API client libraries

```typescript
/// In your library or definition file
import portal from '@ojizero/portal'

const client = portal({ baseUrl: 'some.base.url' }) // Initial configuration can be passed here

// Get method without path variables
client.route('someGetMethod', { path: '/some/path' })

// Get method with path variables
client.route('someGetMethodWithParam', { path: '/some/path/:withInnerVariable' })

export default client

/* ******************* */

/// In your application
import YourClient from 'your-client-module'

const client = YourClient() // You can also pass additional options to futher configure the client

const someGetMethodPromise = client.someGetMethod() // GET http://some.base.url/some/path
const someGetMethodWithParamPromise = client.someGetMethodWithParam(5) // GET http://some.base.url/some/path/5
```

+ 0
- 3
index.js 查看文件

@@ -1,3 +0,0 @@
export default function () {
console.log('Nothing implemented yet.')
}

+ 1736
- 0
package-lock.json
文件差異過大導致無法顯示
查看文件


+ 26
- 4
package.json 查看文件

@@ -1,9 +1,18 @@
{
"name": "@ojizero/portal",
"version": "1.0.0",
"version": "1.0.0-alpha.0",
"description": "HTTP API clients ... simplified.",
"main": "index.js",
"scripts": {},
"main": "dist/index.js",
"publishConfig": {
"access": "public"
},
"scripts": {
"prepare": "npm run clean && npm run build",
"start": "npm test -- --watch --recursive",
"test": "mocha",
"clean": "rm -rf lib",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ojizero/portal.git"
@@ -13,5 +22,18 @@
"bugs": {
"url": "https://github.com/ojizero/portal/issues"
},
"homepage": "https://github.com/ojizero/portal#readme"
"homepage": "https://github.com/ojizero/portal#readme",
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/expect": "^1.20.3",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"ts-node": "^7.0.1",
"typescript": "^3.2.2"
}
}

+ 1
- 0
src/client.ts 查看文件

@@ -0,0 +1 @@
export default class Client {}

+ 57
- 0
src/index.ts 查看文件

@@ -0,0 +1,57 @@
import Client from './client'
import Method from './method'
import Resource from './resource'

export enum AuthenticationTypes {
BasicAuth = 'basic',
TokenAuth = 'token',
KeyAuth = 'key',
BearerAuth = 'bearer',
}

export type Seconds = number

export type BaseUrl = string | URL

export interface Headers {}

export interface Authentication {
type: AuthenticationTypes,
}

export interface Config {
baseUrl: BaseUrl,
headers?: Headers,
authentication?: Authentication,
retries?: number,
timeout?: Seconds,
}

export interface Portal {
route: Method, // TODO: function taking some spec
resource: Resource, // TODO: function taking some spec
_client: Client,
}

export interface Response {
status: {
code: number,
word: string,
},
body: Object | undefined,
headers: Headers,
_rawResponse: string, // raw string response
}

export function createBaseClient (config: Config) /*: Portal*/ {
const client = new Client()

// const portal: Portal = {
// _client: client,
// }

// return portal
return client
}

export default createBaseClient

+ 1
- 0
src/method.ts 查看文件

@@ -0,0 +1 @@
export default class Method {}

+ 1
- 0
src/resource.ts 查看文件

@@ -0,0 +1 @@
export default class Resource {}

+ 5
- 0
test/client.spec.ts 查看文件

@@ -0,0 +1,5 @@
import Client from '../src/client'

describe('Client', () => {
// TODO:
})

+ 3
- 0
test/index.spec.ts 查看文件

@@ -0,0 +1,3 @@
describe('External behaviour', () => {
//
})

+ 3
- 0
test/method.spec.ts 查看文件

@@ -0,0 +1,3 @@
describe('Method', () => {
// TODO:
})

+ 4
- 0
test/mocha.opts 查看文件

@@ -0,0 +1,4 @@
--require ts-node/register
--require ./test/setup.ts
--timeout 30000
test/**/*.spec.ts

+ 3
- 0
test/resource.spec.ts 查看文件

@@ -0,0 +1,3 @@
describe('Resource', () => {
// TODO:
})

+ 9
- 0
test/setup.ts 查看文件

@@ -0,0 +1,9 @@
/// <reference path='typings/globals.d.ts' />

import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

chai.use(chaiAsPromised)

global.chai = chai
global.expect = chai.expect

+ 6
- 0
test/typings/globals.d.ts 查看文件

@@ -0,0 +1,6 @@
declare namespace NodeJS {
interface Global {
chai: any
expect: any
}
}

+ 61
- 0
tsconfig.json 查看文件

@@ -0,0 +1,61 @@
{
"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": [], /* Specify library files to be included in the compilation. */
"allowJs": false,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib",
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": true,
// "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. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "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": [
"./src/**/*.ts"
]
}

+ 23
- 0
tsconfig.spec.json 查看文件

@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
// "compilerOptions": {
// "sourceMap": false,
// "allowJs": false,
// "declaration": false,
// "rootDir": ".",
// "target": "ES6",
// "outDir": "./_tests",
// "moduleResolution": "node",
// "lib": [
// "ES6",
// "ES2015",
// "ES2017.object"
// ]
// },
"include": [
"typings/*",
"test/typings/*",
"src/**/*",
"test/**/*"
]
}

Loading…
取消
儲存