Skip to content
Permalink
Browse files

Initial addition of automatic documentation generation

  • Loading branch information...
maoueh committed Mar 27, 2019
1 parent c32ecc2 commit a10eee6d56510d6aa14899ebfe5de3f25b880b9f
@@ -3,6 +3,7 @@
.envrc

# Build
build/
dist/

# Coverage
@@ -1,8 +1,13 @@
## Coverage
/coverage

## Docs Theme Partials
/docs/theme/partials/*.hbs

## Generated Files
index.js
/build
/dist
/types
*.d.ts

@@ -0,0 +1,5 @@
## Migration Guide

## From `@dfuse/eosws-js` to `@dfuse/client`

To be completed.
@@ -0,0 +1,22 @@
{{#if isInPath}}
</ul>
<ul class="current">
{{/if}}
<li class="{{#if isInPath}}current{{/if}} {{cssClasses}}">
{{#if groupTitle}}
<h3>{{{wbr groupTitle}}}</h3>
{{else}}
<a href="{{relativeURL url}}" class="tsd-kind-icon">{{{wbr title}}}</a>
{{/if}}
{{#if children}}
<ul>
{{#each children}}
{{> toc}}
{{/each}}
</ul>
{{/if}}
</li>
{{#if isInPath}}
</ul>
<ul class="after-current">
{{/if}}
@@ -24,12 +24,14 @@
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"clean": "rimraf dist",
"clean": "rimraf build dist",
"docs": "rimraf build && typedoc",
"prepare": "tsc",
"lint": "tslint **/*.ts",
"lint:specific": "tslint",
"test": "jest",
"run:example": "yarn run ts-node"
"run:example": "yarn run ts-node",
"postinstall": "patch-package"
},
"husky": {
"hooks": {
@@ -56,18 +58,21 @@
"@types/ws": "^6.0.1",
"dotenv": "^6.1.0",
"husky": "^1.1.2",
"isomorphic-ws": "^4.0.1",
"jest": "^24.1.0",
"jest-fetch-mock": "^2.1.1",
"lint-staged": "^7.3.0",
"node-fetch": "^2.3.0",
"patch-package": "^6.0.7",
"postinstall-postinstall": "^2.0.0",
"prettier": "^1.14.3",
"pretty-quick": "^1.8.0",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"typedoc": "^0.14.2",
"typedoc-default-themes-extension": "^0.0.3",
"typedoc-plugin-toc-group": "^0.0.4",
"typescript": "^3.1.3",
"ws": "^6.1.0"
},
@@ -0,0 +1,13 @@
diff --git a/node_modules/typedoc-plugin-toc-group/plugin.js b/node_modules/typedoc-plugin-toc-group/plugin.js
index 264c301..904e26a 100644
--- a/node_modules/typedoc-plugin-toc-group/plugin.js
+++ b/node_modules/typedoc-plugin-toc-group/plugin.js
@@ -47,7 +47,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
isHomePage(page) {
if (page && page.url && page.project) {
try {
- if (page.url.indexOf(page.project[exports.PLUGIN_NAME].homePath) > -1) {
+ if (page.url.indexOf("index.html") > -1 || page.url.indexOf("globals.html") > -1) {
return true;
}
}
@@ -6,13 +6,13 @@ import { OutboundMessageType, OutboundMessage } from "../../message/outbound"
import { DfuseClientError } from "../../types/error"

const message1: OutboundMessage<any> = {
type: OutboundMessageType.HEAD_INFO,
type: OutboundMessageType.GET_HEAD_INFO,
req_id: "1",
data: {}
}

const message2: OutboundMessage<any> = {
type: OutboundMessageType.HEAD_INFO,
type: OutboundMessageType.GET_HEAD_INFO,
req_id: "2",
data: {}
}
@@ -9,22 +9,41 @@ export interface ApiTokenManager {
getTokenInfo: () => Promise<ApiTokenInfo>
}

/**
* Create the standard [[ApiTokenManager]] interface that will manage all the lifecycle
* of a token.
*
* @param fetchTokenInfo The async function that should be used to retrieve a fresh token.
* @param onTokenRefresh The function to call when a token has been refreshed.
* @param delayBuffer The percentage of time to use to schedule the next token refresh
* (i.e. with a value of `0.9` and a token valid for 1000ms from now,
* the next refresh would be scheduled to happen at `now + (0.9 * 1000)`)
* @param apiTokenStore The API token store interface to retrieve token from and to save it back to.
* @param refreshScheduler The scheduler interface that should be used to schedule upcoming refresh token
* and check if a scheduled one already exist.
*
* @kind Factories
*/
export function createApiTokenManager(
fetchTokenInfo: () => Promise<ApiTokenInfo>,
onTokenRefresh: (apiToken: string) => void,
delayBuffer: number,
tokenStore: ApiTokenStore,
apiTokenStore: ApiTokenStore,
refreshScheduler: RefreshScheduler
): ApiTokenManager {
return new DefaultApiTokenManager(
fetchTokenInfo,
onTokenRefresh,
delayBuffer,
tokenStore,
apiTokenStore,
refreshScheduler
)
}

/**
* Check wheter the received [[ApiTokenInfo]] parameter is expired or near its
* expiration.
*/
export function isExpiredOrNearExpiration(tokenInfo: ApiTokenInfo): boolean {
const now = Date.now() / 1000
return tokenInfo.expires_at <= now
@@ -1,10 +1,49 @@
import { ApiTokenInfo } from "../types/auth-token"

/**
* A simple API token store interface supporting async operations. This
* interface is used to store the API token when it has been refreshed
* as well as retrieving a token from the store.
*
* By providing your own [[ApiTokenStore]] implementation, you can for
* example easily store the token in the `localStorage` of the Browser
* if your targeting this environment by rolling your own version:
*
* ```typescript
* class LocalStorageApiTokenStore implements ApiTokenStore {
* async set(apiTokenInfo: ApiTokenInfo): Promise<void> {
* localStorage.set('dfuse-token', JSON.stringify(apiTokenInfo))
* }
*
* async get(apiTokenInfo: ApiTokenInfo): Promise<ApiTokenInfo | undefined> {
* const tokenData = localStorage.get('dfuse-token')
* if (tokenData === null) {
* return undefined
* }
*
* return JSON.parse(tokenData)
* }
* }
* ```
*
* @kind Interfaces
*/
export interface ApiTokenStore {
set: (apiTokenInfo: ApiTokenInfo) => Promise<void>
get: () => Promise<ApiTokenInfo | undefined>
}

/**
* Represents an in-memory token storage concrete implementation of
* a [[ApiTokenStore]]. This simply keep the token in variable and serves
* it from there.
*
* It is **never** persisted and will be reset upon restart of the Browser tab
* or process, leading to a new token being issued.
*
* You should try hard to use a persistent solution so that you re-use the
* same token as long as it's valid.
*/
export class InMemoryApiTokenStore {
private apiTokenInfo?: ApiTokenInfo

@@ -46,7 +46,7 @@ import { StreamClient, Stream, OnStreamMessage } from "../types/stream-client"
import { ApiTokenStore, InMemoryApiTokenStore } from "./api-token-store"
import { RefreshScheduler, createRefreshScheduler } from "./refresh-scheduler"

export interface DfuseClientOptions {
export type DfuseClientOptions = {
network: "mainnet" | "jungle" | "kylin" | string
apiKey: string
secure?: boolean
@@ -65,6 +65,17 @@ export interface DfuseClientOptions {
refreshScheduler?: RefreshScheduler
}

/**
* The main entry point of the library, use it to create the standard [[DfuseClient]]
* instance.
*
* Only the `apiKey` and `network` parameters are mandatory, all others have sane
* default values based on your execution environment (be it a Browser or Node.js).
*
* @param options The options that can be passed to customize [[DfuseClient]] instance, refer to the [[DfuseClientOptions]] for further details.
*
* @kind Factories
*/
export function createDfuseClient(options: DfuseClientOptions): DfuseClient {
const endpoint = networkToEndpoint(options.network)
const secureEndpoint = options.secure === undefined ? true : options.secure
@@ -2,7 +2,7 @@ import { DfuseError, DfuseClientError, DfuseApiError } from "../types/error"
import { Fetch, HttpResponse, HttpQueryParameters, HttpClient } from "../types/http-client"
import debugFactory, { IDebugger } from "debug"

export interface HttpClientOptions {
export type HttpClientOptions = {
fetch?: Fetch
}

@@ -5,7 +5,7 @@ import { InboundMessage, InboundMessageType } from "../message/inbound"
import { DfuseClientError } from "../types/error"
import { WebSocket, Socket, SocketMessageListener, WebSocketFactory } from "../types/socket"

export interface SocketOptions {
export type SocketOptions = {
id?: string
autoReconnect?: boolean
reconnectDelayInMs?: number
@@ -6,7 +6,7 @@ import { DfuseClientError } from "../types/error"
import { StreamClient, OnStreamMessage, Stream } from "../types/stream-client"
import { Socket } from "../types/socket"

export interface StreamClientOptions {
export type StreamClientOptions = {
socket?: Socket
socketOptions?: SocketOptions
}
@@ -1,4 +1,4 @@
export interface InboundMessage<T> {
export type InboundMessage<T> = {
type: InboundMessageType
req_id?: string
data: T
@@ -1,6 +1,6 @@
import { DfuseClientError } from "../types/error"

export interface OutboundMessage<T> {
export type OutboundMessage<T> = {
type: OutboundMessageType
req_id: string
listen?: boolean
@@ -19,15 +19,15 @@ export enum OutboundMessageType {
UNLISTEN = "unlisten"
}

export interface StreamOptions {
export type StreamOptions = {
listen?: boolean
req_id?: string
start_block?: number
fetch?: boolean
with_progress?: number
}

export interface GetActionTracesMessageData {
export type GetActionTracesMessageData = {
account?: string // @deprecated, will be removed in next major bump
accounts?: string
receiver?: string // @deprecated, will be removed in next major bump
@@ -52,7 +52,7 @@ export function getActionTracesMessage(
)
}

export interface GetTableRowsMessageData {
export type GetTableRowsMessageData = {
code: string
scope: string
table: string
@@ -73,7 +73,7 @@ export function getTableRowsMessage(
)
}

export interface GetTransactionLifecycleMessageData {
export type GetTransactionLifecycleMessageData = {
id: string
}

@@ -100,7 +100,7 @@ export function getHeadInfoMessage(
)
}

export interface UnlistenMessageData {
export type UnlistenMessageData = {
req_id: string
}

@@ -1,11 +1,11 @@
export interface ActionTraceData<T> {
export type ActionTraceData<T> = {
trx_id: string
idx: number
depth: number
trace: ActionTrace<T>
}

export interface ActionTrace<T> {
export type ActionTrace<T> = {
receipt: ActionReceipt
act: Action<T>
elapsed: number
@@ -16,20 +16,20 @@ export interface ActionTrace<T> {
inline_traces: Array<ActionTrace<any>>
}

export interface Action<T> {
export type Action<T> = {
account: string
name: string
authorization: Authorization[]
data: T
hex_data: string
}

export interface Authorization {
export type Authorization = {
actor: string
permission: string
}

export interface ActionReceipt {
export type ActionReceipt = {
receiver: string
act_digest: string
global_sequence: number
@@ -1,6 +1,6 @@
export type AuthTokenResponse = ApiTokenInfo

export interface ApiTokenInfo {
export type ApiTokenInfo = {
token: string
expires_at: number
}
@@ -21,6 +21,9 @@ import {

export type RequestIdGenerator = () => string

/**
* @group Interfaces
*/
export interface DfuseClient {
//
/// WebSocket API
@@ -1,4 +1,4 @@
export interface ErrorData {
export type ErrorData = {
code: string
trace_id?: string
message: string
@@ -1,4 +1,4 @@
export interface HeadInfoData {
export type HeadInfoData = {
last_irreversible_block_num: number
last_irreversible_block_id: string
head_block_num: number

0 comments on commit a10eee6

Please sign in to comment.
You can’t perform that action at this time.