Skip to content

Commit

Permalink
feat: 更新Meta构造方法的参数顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
zman committed Sep 16, 2020
1 parent d5c3247 commit 7b2abe1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ dist
compiled
.awcache
.rpt2_cache
*.tgz
30 changes: 17 additions & 13 deletions README.md
@@ -1,25 +1,29 @@
# @zman2013/ts-apollo-client

[![Build Status](https://travis-ci.org/zman/ts-apollo-client.svg)](https://travis-ci.org/zman/ts-apollo-client)
[![Coverage Status](https://coveralls.io/repos/github/zman/ts-apollo-client/badge.svg)](https://coveralls.io/github/zman/ts-apollo-client)
[![Build Status](https://github.com/zman2013/ts-apollo-client/workflows/Build%20and%20Release/badge.svg)](https://github.com/zman2013/ts-apollo-client/workflows/Build%20and%20Release/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/zman2013/ts-apollo-client/badge.svg?branch=master)](https://coveralls.io/github/zman2013/ts-apollo-client?branch=master)
[![npm](https://img.shields.io/npm/v/@zman2013/ts-apollo-client.svg)](https://www.npmjs.com/package/@zman2013/ts-apollo-client/)

> A starter project that makes creating a TypeScript module extremely easy.
## Intro.

This tool is a modification of [typescript-library-starter](https://github.com/alexjoverm/typescript-library-starter), I'm using it to create Node.JS modules.
> A TypeScript implementation of a client for Apollo(https://github.com/ctripcorp/apollo), the reliable configuration management system.
## Usage

```bash
git clone https://github.com/jacobbubu/typescript-starter.git YOURFOLDERNAME
cd YOURFOLDERNAME
npm install
npm install @zman2013/ts-apollo-client
```

**Start coding!** `package.json` and entry files are already set up for you, so don't worry about linking to your main file, typings, etc. Just keep those files with the same name.
### example1
```typescript
import * as client from '@zman2013/ts-apollo-client'

## Features
const meta = new client.Meta('http://xxx', 'appId')
client.getConfig(meta).then(json => console.log(json))
```
### example2 - multiple namespaces
```typescript
import * as client from '@zman2013/ts-apollo-client'

const meta = new client.Meta('http://xxx', 'appId', ['application', 'common'])
client.getConfig(meta).then(json => console.log(json))
```

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
4 changes: 2 additions & 2 deletions package.json
@@ -1,14 +1,14 @@
{
"name": "@zman2013/ts-apollo-client",
"version": "0.0.0",
"version": "0.0.1",
"description": "",
"keywords": [],
"main": "dist/index.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist"
],
"author": "zman <manzhiyuan@lixiang.com>",
"author": "zman2013 <vsmingren@qq.com>",
"repository": {
"type": "git",
"url": ""
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Expand Up @@ -6,8 +6,8 @@ export class Meta {
constructor(
readonly serverUrl: string,
readonly appId: string,
readonly clusterName: string = 'default',
readonly namespaceNames: string[] = ['application'],
readonly clusterName: string = 'default',
readonly releaseKey?: string,
readonly clientIp?: string
) {}
Expand All @@ -29,8 +29,6 @@ export async function getConfig(meta: Meta): Promise<Object> {
const bundle = await Promise.all(uris.map(uri => urllib.request(uri, options)))

for (let res of bundle) {
console.log(res)
// assert 作用,没有抛出异常
assert(res.status === 200, 'request apollo config failed, http status: ' + res.status)
}

Expand Down
12 changes: 7 additions & 5 deletions test/basic.test.ts
Expand Up @@ -15,10 +15,12 @@ describe('Basic Test', () => {
})

it('two namespaces', done => {
const apolloMeta = new client.Meta('http://two', 'mock-appId', 'default', [
'application',
'common'
])
const apolloMeta = new client.Meta(
'http://two',
'mock-appId',
['application', 'common'],
'default'
)

client
.getConfig(apolloMeta)
Expand All @@ -42,9 +44,9 @@ describe('Basic Test', () => {
const apolloMeta = new client.Meta(
'http://xxx',
'mock-appId',
'',
['application'],
'',
'',
'mock-clientIp'
)

Expand Down

0 comments on commit 7b2abe1

Please sign in to comment.