From 58296325aa33d943a1caed60b8c5438b5d4bd2d9 Mon Sep 17 00:00:00 2001 From: Ragg Date: Wed, 28 Feb 2018 01:26:21 +0900 Subject: [PATCH 01/22] Add `dispatchr` typing --- types/dispatchr/addons/BaseStore.d.ts | 17 +++++++ types/dispatchr/addons/createStore.d.ts | 15 ++++++ types/dispatchr/dispatchr-test.ts | 28 +++++++++++ types/dispatchr/index.d.ts | 62 +++++++++++++++++++++++++ types/dispatchr/tsconfig.json | 25 ++++++++++ types/dispatchr/tslint.json | 1 + 6 files changed, 148 insertions(+) create mode 100644 types/dispatchr/addons/BaseStore.d.ts create mode 100644 types/dispatchr/addons/createStore.d.ts create mode 100644 types/dispatchr/dispatchr-test.ts create mode 100644 types/dispatchr/index.d.ts create mode 100644 types/dispatchr/tsconfig.json create mode 100644 types/dispatchr/tslint.json diff --git a/types/dispatchr/addons/BaseStore.d.ts b/types/dispatchr/addons/BaseStore.d.ts new file mode 100644 index 0000000000..9e5e4888c3 --- /dev/null +++ b/types/dispatchr/addons/BaseStore.d.ts @@ -0,0 +1,17 @@ +// TypeScript Version: 2.3 +/// + +import { Dispatcher, DispatcherInterface, DispatcherContext, Store } from 'dispatchr'; +import { EventEmitter } from 'events'; + +declare class BaseStore extends EventEmitter implements Store { + constructor(dispatcher: DispatcherInterface); + initialize?: () => void; + getContext(): DispatcherContext; + addChangeListener(callback: () => void): void; + removeChangeListener(callback: () => void): void; + shouldDehydrate(): boolean; + emitChange(): void; +} + +export = BaseStore; diff --git a/types/dispatchr/addons/createStore.d.ts b/types/dispatchr/addons/createStore.d.ts new file mode 100644 index 0000000000..11fe076a8f --- /dev/null +++ b/types/dispatchr/addons/createStore.d.ts @@ -0,0 +1,15 @@ +// TypeScript Version: 2.3 +import { StoreClass, Store } from 'dispatchr'; + +interface StoreOptions { + initialize?(): void; + storeName: string; + handlers: { [event: string]: string }; +} + +type CreateStoreOption = ThisType & StoreOptions & { [key: string]: any }; + +type CreateStore = (options: CreateStoreOption) => StoreClass; + +declare const _: CreateStore; +export = _; diff --git a/types/dispatchr/dispatchr-test.ts b/types/dispatchr/dispatchr-test.ts new file mode 100644 index 0000000000..816e6fb3bd --- /dev/null +++ b/types/dispatchr/dispatchr-test.ts @@ -0,0 +1,28 @@ +import { createDispatcher, Store } from 'dispatchr'; +import * as createStore from 'dispatchr/addons/createStore'; + +const TestStore = createStore({ + storeName: 'TestStore', + + handlers: { + ACTION_NAME: 'actionHandler' + }, + + initialize() { }, + + actionHandler() { + this.emitChange(); + } +}); + +const dispatcher = createDispatcher({ + errorHandler(e, context) { + e.meta; + e.type; + e.message; + }, + stores: [TestStore] +}); + +const context = dispatcher.createContext({}); +context.dispatch('ACTION_NAME', {}); diff --git a/types/dispatchr/index.d.ts b/types/dispatchr/index.d.ts new file mode 100644 index 0000000000..f245c5f728 --- /dev/null +++ b/types/dispatchr/index.d.ts @@ -0,0 +1,62 @@ +// TypeScript Version: 2.3 +/// +import { EventEmitter } from 'events'; + +export interface DispatcherState { + stores: { [storeName: string]: any }; +} + +export interface DispatcherOption { + stores?: StoreClass[]; + errorHandler?: (e: DispatcherError, context: DispatcherContext) => void; +} + +export interface StoreClass { + storeName: string; + new(): Store; +} + +export interface Store extends EventEmitter { + dehydrate?(): S; + rehydrate?(state: S): void; + shouldDehydrate?(): boolean; + emitChange(): void; +} + +export interface Dispatcher { + createContext(context: {}): DispatcherContext; + registerStore(store: StoreClass): void; + isRegistered(store: StoreClass | string): boolean; + getStoreName(store: StoreClass | string): string; +} + +export interface DispatcherInterface { + getContext(): DispatcherContext; + getStore: DispatcherContext['getStore']; + waitFor: DispatcherContext['waitFor']; +} + +export interface DispatcherContext { + getStore(name: string): Store; + getStore(name: T): T; + + dispatch(actionName: string, payload: any): void; + + dehydrate(): DispatcherState; + rehydrate(dispatcherState: DispatcherState): void; + + waitFor(stores: Array, callback: () => void): void; + dispatcherInterface: DispatcherInterface; +} + +export interface DispatcherError { + message: string; + type: string; + meta: { + actionName?: string, + payload?: any, + error: Error + }; +} + +export function createDispatcher(options: DispatcherOption): Dispatcher; diff --git a/types/dispatchr/tsconfig.json b/types/dispatchr/tsconfig.json new file mode 100644 index 0000000000..3a2ad998e2 --- /dev/null +++ b/types/dispatchr/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "addons/BaseStore.d.ts", + "addons/createStore.d.ts", + "dispatchr-test.ts" + ] + } diff --git a/types/dispatchr/tslint.json b/types/dispatchr/tslint.json new file mode 100644 index 0000000000..c17ac4dd6d --- /dev/null +++ b/types/dispatchr/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dtslint.json" } From 0b1f1c3e872fd8feb516867248e53831d756f2b8 Mon Sep 17 00:00:00 2001 From: Ragg Date: Wed, 28 Feb 2018 02:07:03 +0900 Subject: [PATCH 02/22] Improve createStore() type --- types/dispatchr/addons/createStore.d.ts | 5 ++--- types/dispatchr/dispatchr-test.ts | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/types/dispatchr/addons/createStore.d.ts b/types/dispatchr/addons/createStore.d.ts index 11fe076a8f..a62425f9ae 100644 --- a/types/dispatchr/addons/createStore.d.ts +++ b/types/dispatchr/addons/createStore.d.ts @@ -5,11 +5,10 @@ interface StoreOptions { initialize?(): void; storeName: string; handlers: { [event: string]: string }; + [prop: string]: any; } -type CreateStoreOption = ThisType & StoreOptions & { [key: string]: any }; - -type CreateStore = (options: CreateStoreOption) => StoreClass; +type CreateStore = (options: This & ThisType) => StoreClass; declare const _: CreateStore; export = _; diff --git a/types/dispatchr/dispatchr-test.ts b/types/dispatchr/dispatchr-test.ts index 816e6fb3bd..3c26c50c9b 100644 --- a/types/dispatchr/dispatchr-test.ts +++ b/types/dispatchr/dispatchr-test.ts @@ -12,7 +12,10 @@ const TestStore = createStore({ actionHandler() { this.emitChange(); - } + this.additionalMethod(); + }, + + additionalMethod() {} }); const dispatcher = createDispatcher({ From d08933b8f62b5afd7fd1a23a5bde65054ae56c35 Mon Sep 17 00:00:00 2001 From: Ragg Date: Wed, 28 Feb 2018 02:15:17 +0900 Subject: [PATCH 03/22] Regenerate by dts-gen --- types/dispatchr/{dispatchr-test.ts => dispatchr-tests.ts} | 0 types/dispatchr/index.d.ts | 4 ++++ types/dispatchr/tsconfig.json | 6 +++--- types/dispatchr/tslint.json | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) rename types/dispatchr/{dispatchr-test.ts => dispatchr-tests.ts} (100%) diff --git a/types/dispatchr/dispatchr-test.ts b/types/dispatchr/dispatchr-tests.ts similarity index 100% rename from types/dispatchr/dispatchr-test.ts rename to types/dispatchr/dispatchr-tests.ts diff --git a/types/dispatchr/index.d.ts b/types/dispatchr/index.d.ts index f245c5f728..f9f31739fd 100644 --- a/types/dispatchr/index.d.ts +++ b/types/dispatchr/index.d.ts @@ -1,3 +1,7 @@ +// Type definitions for dispatchr 1.2 +// Project: https://github.com/yahoo/fluxible#readme +// Definitions by: Ragg +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// import { EventEmitter } from 'events'; diff --git a/types/dispatchr/tsconfig.json b/types/dispatchr/tsconfig.json index 3a2ad998e2..47109880da 100644 --- a/types/dispatchr/tsconfig.json +++ b/types/dispatchr/tsconfig.json @@ -18,8 +18,8 @@ }, "files": [ "index.d.ts", - "addons/BaseStore.d.ts", "addons/createStore.d.ts", - "dispatchr-test.ts" + "addons/BaseStore.d.ts", + "dispatchr-tests.ts" ] - } +} diff --git a/types/dispatchr/tslint.json b/types/dispatchr/tslint.json index c17ac4dd6d..3db14f85ea 100644 --- a/types/dispatchr/tslint.json +++ b/types/dispatchr/tslint.json @@ -1 +1 @@ -{ "extends": "dtslint/dtslint.json" } +{ "extends": "dtslint/dt.json" } From e85eb95d786b6d333c94ec952f8f0ed1bf230645 Mon Sep 17 00:00:00 2001 From: Ragg Date: Wed, 28 Feb 2018 02:29:55 +0900 Subject: [PATCH 04/22] Fix for test --- types/dispatchr/addons/BaseStore.d.ts | 3 +-- types/dispatchr/addons/createStore.d.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/types/dispatchr/addons/BaseStore.d.ts b/types/dispatchr/addons/BaseStore.d.ts index 9e5e4888c3..0c1c577a3f 100644 --- a/types/dispatchr/addons/BaseStore.d.ts +++ b/types/dispatchr/addons/BaseStore.d.ts @@ -1,7 +1,6 @@ -// TypeScript Version: 2.3 /// -import { Dispatcher, DispatcherInterface, DispatcherContext, Store } from 'dispatchr'; +import { Dispatcher, DispatcherInterface, DispatcherContext, Store } from '../index'; import { EventEmitter } from 'events'; declare class BaseStore extends EventEmitter implements Store { diff --git a/types/dispatchr/addons/createStore.d.ts b/types/dispatchr/addons/createStore.d.ts index a62425f9ae..0c6388d1ae 100644 --- a/types/dispatchr/addons/createStore.d.ts +++ b/types/dispatchr/addons/createStore.d.ts @@ -1,5 +1,4 @@ -// TypeScript Version: 2.3 -import { StoreClass, Store } from 'dispatchr'; +import { StoreClass, Store } from '../index'; interface StoreOptions { initialize?(): void; From 99a18f011384596248ea2d5a8cebf4c26d1e6cba Mon Sep 17 00:00:00 2001 From: Ragg Date: Wed, 28 Feb 2018 02:32:08 +0900 Subject: [PATCH 05/22] to ReadonlyArray --- types/dispatchr/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/dispatchr/index.d.ts b/types/dispatchr/index.d.ts index f9f31739fd..3fa0118729 100644 --- a/types/dispatchr/index.d.ts +++ b/types/dispatchr/index.d.ts @@ -49,7 +49,7 @@ export interface DispatcherContext { dehydrate(): DispatcherState; rehydrate(dispatcherState: DispatcherState): void; - waitFor(stores: Array, callback: () => void): void; + waitFor(stores: ReadonlyArray, callback: () => void): void; dispatcherInterface: DispatcherInterface; } From 01aa7a6ff452e42e90be95d47e5a116e7249a831 Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:23:53 +0900 Subject: [PATCH 06/22] Improve typing for createStore (review fixes) --- types/dispatchr/addons/createStore.d.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/types/dispatchr/addons/createStore.d.ts b/types/dispatchr/addons/createStore.d.ts index 0c6388d1ae..df8e12cf03 100644 --- a/types/dispatchr/addons/createStore.d.ts +++ b/types/dispatchr/addons/createStore.d.ts @@ -1,13 +1,20 @@ import { StoreClass, Store } from '../index'; +type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; +type Omit = Pick>; + interface StoreOptions { - initialize?(): void; storeName: string; handlers: { [event: string]: string }; - [prop: string]: any; + statics?: { [prop: string]: any }; + mixins?: object[]; + initialize?(): void; + dehydrate?(): any; + rehydrate?(state: any): void; } -type CreateStore = (options: This & ThisType) => StoreClass; +// see: https://github.com/yahoo/fluxible/blob/dispatchr-v1.2.0/packages/dispatchr/addons/createStore.js#L9 +type StoreThis = Omit & Store -declare const _: CreateStore; -export = _; +declare function createStore(options: T & ThisType>): StoreClass; +export = createStore; From 088f244955d98cbe794fcdaa4c4473ee830379a3 Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:24:38 +0900 Subject: [PATCH 07/22] Arrow function type to method type --- types/dispatchr/addons/BaseStore.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/dispatchr/addons/BaseStore.d.ts b/types/dispatchr/addons/BaseStore.d.ts index 0c1c577a3f..6507a7fcf4 100644 --- a/types/dispatchr/addons/BaseStore.d.ts +++ b/types/dispatchr/addons/BaseStore.d.ts @@ -5,7 +5,7 @@ import { EventEmitter } from 'events'; declare class BaseStore extends EventEmitter implements Store { constructor(dispatcher: DispatcherInterface); - initialize?: () => void; + initialize?(): void; getContext(): DispatcherContext; addChangeListener(callback: () => void): void; removeChangeListener(callback: () => void): void; From 06f37f7a26f27c94f9199e301741991550494706 Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:25:07 +0900 Subject: [PATCH 08/22] Add BaseStore test --- types/dispatchr/dispatchr-tests.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/types/dispatchr/dispatchr-tests.ts b/types/dispatchr/dispatchr-tests.ts index 3c26c50c9b..4097b14af3 100644 --- a/types/dispatchr/dispatchr-tests.ts +++ b/types/dispatchr/dispatchr-tests.ts @@ -1,5 +1,6 @@ import { createDispatcher, Store } from 'dispatchr'; import * as createStore from 'dispatchr/addons/createStore'; +import * as BaseStore from 'dispatchr/addons/BaseStore'; const TestStore = createStore({ storeName: 'TestStore', @@ -18,6 +19,16 @@ const TestStore = createStore({ additionalMethod() {} }); +class ExtendedStore extends BaseStore<{}> { + static handlers = { + ACTION_NAME: 'actionHandler' + }; + + actionHandler() { + this.emitChange(); + } +} + const dispatcher = createDispatcher({ errorHandler(e, context) { e.meta; From 020a99332b38d167262312f6f264a64f936732ad Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:32:20 +0900 Subject: [PATCH 09/22] Add createStore `statics` test --- types/dispatchr/dispatchr-tests.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/dispatchr/dispatchr-tests.ts b/types/dispatchr/dispatchr-tests.ts index 4097b14af3..4c66c47b65 100644 --- a/types/dispatchr/dispatchr-tests.ts +++ b/types/dispatchr/dispatchr-tests.ts @@ -9,6 +9,10 @@ const TestStore = createStore({ ACTION_NAME: 'actionHandler' }, + statics: { + staticMethod() {} + }, + initialize() { }, actionHandler() { From faf8f5f20700d214f56427063dfccc16416ad55f Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:35:03 +0900 Subject: [PATCH 10/22] lint --- types/dispatchr/addons/createStore.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/dispatchr/addons/createStore.d.ts b/types/dispatchr/addons/createStore.d.ts index df8e12cf03..86a1f24fbb 100644 --- a/types/dispatchr/addons/createStore.d.ts +++ b/types/dispatchr/addons/createStore.d.ts @@ -14,7 +14,7 @@ interface StoreOptions { } // see: https://github.com/yahoo/fluxible/blob/dispatchr-v1.2.0/packages/dispatchr/addons/createStore.js#L9 -type StoreThis = Omit & Store +type StoreThis = Omit & Store; declare function createStore(options: T & ThisType>): StoreClass; export = createStore; From 528492dd9314556edd310c924310078164ca2cda Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:35:48 +0900 Subject: [PATCH 11/22] Fix import syntax --- types/dispatchr/dispatchr-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/dispatchr/dispatchr-tests.ts b/types/dispatchr/dispatchr-tests.ts index 4c66c47b65..797cb9fb0a 100644 --- a/types/dispatchr/dispatchr-tests.ts +++ b/types/dispatchr/dispatchr-tests.ts @@ -1,6 +1,6 @@ import { createDispatcher, Store } from 'dispatchr'; -import * as createStore from 'dispatchr/addons/createStore'; -import * as BaseStore from 'dispatchr/addons/BaseStore'; +import createStore = require('dispatchr/addons/createStore'); +import BaseStore = require('dispatchr/addons/BaseStore'); const TestStore = createStore({ storeName: 'TestStore', From c85dafb61e5629bc3a280f952fe44c684e4cf7d5 Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:36:30 +0900 Subject: [PATCH 12/22] empty {} -> object --- types/dispatchr/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/dispatchr/index.d.ts b/types/dispatchr/index.d.ts index 3fa0118729..3b4dab9ec1 100644 --- a/types/dispatchr/index.d.ts +++ b/types/dispatchr/index.d.ts @@ -28,7 +28,7 @@ export interface Store extends EventEmitter { } export interface Dispatcher { - createContext(context: {}): DispatcherContext; + createContext(context: object): DispatcherContext; registerStore(store: StoreClass): void; isRegistered(store: StoreClass | string): boolean; getStoreName(store: StoreClass | string): string; From 6b42020bf237e2422cd6b42a374ebc61ddbc533b Mon Sep 17 00:00:00 2001 From: Ragg Date: Thu, 1 Mar 2018 00:44:46 +0900 Subject: [PATCH 13/22] lint --- types/dispatchr/dispatchr-tests.ts | 2 +- types/dispatchr/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/dispatchr/dispatchr-tests.ts b/types/dispatchr/dispatchr-tests.ts index 797cb9fb0a..fcf0490f44 100644 --- a/types/dispatchr/dispatchr-tests.ts +++ b/types/dispatchr/dispatchr-tests.ts @@ -23,7 +23,7 @@ const TestStore = createStore({ additionalMethod() {} }); -class ExtendedStore extends BaseStore<{}> { +class ExtendedStore extends BaseStore { static handlers = { ACTION_NAME: 'actionHandler' }; diff --git a/types/dispatchr/index.d.ts b/types/dispatchr/index.d.ts index 3b4dab9ec1..b5cf63009d 100644 --- a/types/dispatchr/index.d.ts +++ b/types/dispatchr/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/yahoo/fluxible#readme // Definitions by: Ragg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.5 /// import { EventEmitter } from 'events'; From 393813902921572fbb99fd1a3f628a64edaf716b Mon Sep 17 00:00:00 2001 From: Nick Whyte Date: Fri, 9 Mar 2018 12:26:09 +1100 Subject: [PATCH 14/22] prismic-dom: Add initial typings --- types/prismic-dom/index.d.ts | 8 ++++++++ types/prismic-dom/prismic-dom-tests.ts | 3 +++ types/prismic-dom/tsconfig.json | 22 ++++++++++++++++++++++ types/prismic-dom/tslint.json | 1 + 4 files changed, 34 insertions(+) create mode 100644 types/prismic-dom/index.d.ts create mode 100644 types/prismic-dom/prismic-dom-tests.ts create mode 100644 types/prismic-dom/tsconfig.json create mode 100644 types/prismic-dom/tslint.json diff --git a/types/prismic-dom/index.d.ts b/types/prismic-dom/index.d.ts new file mode 100644 index 0000000000..9588f1e25c --- /dev/null +++ b/types/prismic-dom/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for prismic-dom 2.0 +// Project: https://github.com/prismicio/prismic-dom#readme +// Definitions by: Nick Whyte +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class RichText { + static asHtml(richText: any, linkResolver?: (doc: any) => string): string; +} diff --git a/types/prismic-dom/prismic-dom-tests.ts b/types/prismic-dom/prismic-dom-tests.ts new file mode 100644 index 0000000000..9e123002f1 --- /dev/null +++ b/types/prismic-dom/prismic-dom-tests.ts @@ -0,0 +1,3 @@ +import prismicDom = require("prismic-dom"); + +let rendered: string = prismicDom.RichText.asHtml({}); diff --git a/types/prismic-dom/tsconfig.json b/types/prismic-dom/tsconfig.json new file mode 100644 index 0000000000..ef0b24f3a7 --- /dev/null +++ b/types/prismic-dom/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "prismic-dom-tests.ts" + ] +} diff --git a/types/prismic-dom/tslint.json b/types/prismic-dom/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/prismic-dom/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 4377692a9b1e3dd06c9e7a9c1ce4d5e7a237d02c Mon Sep 17 00:00:00 2001 From: Nick Whyte Date: Fri, 9 Mar 2018 12:28:40 +1100 Subject: [PATCH 15/22] . --- types/prismic-dom/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/prismic-dom/tsconfig.json b/types/prismic-dom/tsconfig.json index ef0b24f3a7..0687e7ae0e 100644 --- a/types/prismic-dom/tsconfig.json +++ b/types/prismic-dom/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 2f3607131c9716b01fcd7e7f76cb82764fb9b4ac Mon Sep 17 00:00:00 2001 From: Nick Whyte Date: Fri, 9 Mar 2018 12:32:31 +1100 Subject: [PATCH 16/22] . --- types/prismic-dom/index.d.ts | 6 +++--- types/prismic-dom/prismic-dom-tests.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/types/prismic-dom/index.d.ts b/types/prismic-dom/index.d.ts index 9588f1e25c..82c766fda6 100644 --- a/types/prismic-dom/index.d.ts +++ b/types/prismic-dom/index.d.ts @@ -1,8 +1,8 @@ // Type definitions for prismic-dom 2.0 // Project: https://github.com/prismicio/prismic-dom#readme -// Definitions by: Nick Whyte +// Definitions by: Nick Whyte // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export class RichText { - static asHtml(richText: any, linkResolver?: (doc: any) => string): string; +export namespace RichText { + function asHtml(richText: any, linkResolver?: (doc: any) => string): string; } diff --git a/types/prismic-dom/prismic-dom-tests.ts b/types/prismic-dom/prismic-dom-tests.ts index 9e123002f1..598573cced 100644 --- a/types/prismic-dom/prismic-dom-tests.ts +++ b/types/prismic-dom/prismic-dom-tests.ts @@ -1,3 +1,3 @@ import prismicDom = require("prismic-dom"); -let rendered: string = prismicDom.RichText.asHtml({}); +const rendered: string = prismicDom.RichText.asHtml({}); From 6a74caff79264a15bbc738e62109ed497e0a45da Mon Sep 17 00:00:00 2001 From: Carl Foster Date: Fri, 9 Mar 2018 11:59:33 +1000 Subject: [PATCH 17/22] Add types for stellar-sdk --- types/stellar-sdk/index.d.ts | 862 +++++++++++++++++++++++++ types/stellar-sdk/stellar-sdk-tests.ts | 9 + types/stellar-sdk/tsconfig.json | 23 + types/stellar-sdk/tslint.json | 7 + 4 files changed, 901 insertions(+) create mode 100644 types/stellar-sdk/index.d.ts create mode 100644 types/stellar-sdk/stellar-sdk-tests.ts create mode 100644 types/stellar-sdk/tsconfig.json create mode 100644 types/stellar-sdk/tslint.json diff --git a/types/stellar-sdk/index.d.ts b/types/stellar-sdk/index.d.ts new file mode 100644 index 0000000000..307c6b44af --- /dev/null +++ b/types/stellar-sdk/index.d.ts @@ -0,0 +1,862 @@ +// Type definitions for stellar-sdk 0.8 +// Project: https://github.com/stellar/js-stellar-sdk +// Definitions by: Carl Foster +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// + +export class Account { + constructor(accountId: string, sequence: string | number) + accountId(): string + sequenceNumber(): string + incrementSequenceNumber(): void +} + +export class CallBuilder { + constructor(serverUrl: string) + call(): Promise> + cursor(cursor: string): this + limit(limit: number): this + order(direction: 'asc' | 'desc'): this + stream(options?: { onmessage?: () => void, onerror?: () => void }): () => void +} + +export interface CollectionPage { + records: T[], + next: () => Promise>, + prev: () => Promise>, +} + +export interface Record { + _links: { + [key: string]: RecordLink + } +} + +export interface RecordLink { + href: string + templated?: boolean +} + +/* Due to a bug with the recursive function requests */ +export interface CollectionRecord { + _links: { + next: RecordLink + prev: RecordLink + self: RecordLink + } + _embedded: { + records: T[] + } +} + +export interface CallFunctionTemplateOptions { + cursor?: string | number + limit?: number + order?: 'asc' | 'desc' +} + +export type CallFunction = () => Promise +export type CallCollectionFunction = + (options?: CallFunctionTemplateOptions) => Promise> + +export interface AccountRecord extends Record { + id: string + paging_token: string + account_id: string + sequence: number + subentry_count: number + thresholds: { + low_threshold: number + med_threshold: number + high_threshold: number + } + flags: { + auth_required: boolean + auth_revocable: boolean + } + balances: Array< + { + balance: string + asset_type: 'native' + } | + { + balance: string + limit: string + asset_type: 'credit_alphanum4' | 'credit_alphanum12' + asset_code: string + asset_issuer: string + } + > + signers: Array< + { + _key: string + weight: number + } + > + data: { + [key: string]: string + } + + effects: CallCollectionFunction + offers: CallCollectionFunction + operations: CallCollectionFunction + payments: CallCollectionFunction + trades: CallCollectionFunction +} + +export interface AssetRecord extends Record { + asset_type: 'credit_alphanum4' | 'credit_alphanum12' + asset_code: string + asset_issuer: string + paging_token: string + amount: string + num_accounts: number + flags: { + auth_required: boolean + auth_revocable: boolean + } +} + +export interface EffectRecord extends Record { + account: string + paging_token: string + starting_balance: string + type_i: string + type: string + + operation?: CallFunction + precedes?: CallFunction + succeeds?: CallFunction +} + +export interface LedgerRecord extends Record { + id: string + paging_token: string + hash: string + prev_hash: string + sequence: number + transaction_count: number + operation_count: number + closed_at: string + total_coins: string + fee_pool: string + base_fee: number + base_reserve: string + max_tx_set_size: number + protocol_version: number + header_xdr: string + base_fee_in_stroops: number + base_reserve_in_stroops: number + + effects: CallCollectionFunction + operations: CallCollectionFunction + self: CallFunction + transactions: CallCollectionFunction +} + +export interface OfferRecord extends Record { + id: string + paging_token: string + seller_attr: string + selling: Asset + buying: Asset + amount: string + price_r: { numerator: number, denominator: number } + price: string + + seller?: CallFunction +} + +export interface BaseOperationRecord extends Record { + id: string + paging_token: string + type: string + type_i: number + + self: CallFunction + succeeds: CallFunction + precedes: CallFunction + effects: CallCollectionFunction + transaction: CallFunction +} + +export interface CreateAccountOperationRecord extends BaseOperationRecord { + type: 'create_account' + account: string + funder: string + starting_balance: string +} + +export interface PaymentOperationRecord extends BaseOperationRecord { + type: 'payment' + from: string + to: string + asset_type: string + asset_code?: string + asset_issuer?: string + amount: string + + sender: CallFunction + receiver: CallFunction +} + +export interface PathPaymentOperationRecord extends BaseOperationRecord { + type: 'path_payment' + from: string + to: string + asset_code?: string + asset_issuer?: string + asset_type: string + amount: string + source_asset_code?: string + source_asset_issuer?: string + source_asset_type: string + source_max: string + source_amount: string +} + +export interface ManageOfferOperationRecord extends BaseOperationRecord { + type: 'manage_offer' + offer_id: number + amount: string + buying_asset_code?: string + buying_asset_issuer?: string + buying_asset_type: string + price: string + price_r: { numerator: number, denominator: number } + selling_asset_code?: string + selling_asset_issuer?: string + selling_asset_type: string +} + +export interface PassiveOfferOperationRecord extends BaseOperationRecord { + type: 'create_passive_offer' + offer_id: number + amount: string + buying_asset_code?: string + buying_asset_issuer?: string + buying_asset_type: string + price: string + price_r: { numerator: number, denominator: number } + selling_asset_code?: string + selling_asset_issuer?: string + selling_asset_type: string +} + +export interface SetOptionsOperationRecord extends BaseOperationRecord { + type: 'set_options' + signer_key?: string + signer_weight?: number + master_key_weight?: number + low_threshold?: number + med_threshold?: number + high_threshold?: number + home_domain?: string + set_flags: Array<(1 | 2)> + set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')> + clear_flags: Array<(1 | 2)> + clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')> +} + +export interface ChangeTrustOperationRecord extends BaseOperationRecord { + type: 'change_trust' + asset_code: string + asset_issuer: string + asset_type: string + trustee: string + trustor: string + limit: string +} + +export interface AllowTrustOperationRecord extends BaseOperationRecord { + type: 'allow_trust' + asset_code: string + asset_issuer: string + asset_type: string + authorize: boolean + trustee: string + trustor: string +} + +export interface AccountMergeOperationRecord extends BaseOperationRecord { + type: 'account_merge' + into: string +} + +export interface InflationOperationRecord extends BaseOperationRecord { + type: 'inflation' +} + +export interface ManageDataOperationRecord extends BaseOperationRecord { + type: 'manage_data' + name: string + value: string +} + +export type OperationRecord = CreateAccountOperationRecord + | PaymentOperationRecord + | PathPaymentOperationRecord + | ManageOfferOperationRecord + | PassiveOfferOperationRecord + | SetOptionsOperationRecord + | ChangeTrustOperationRecord + | AllowTrustOperationRecord + | AccountMergeOperationRecord + | InflationOperationRecord + | ManageDataOperationRecord + +export interface OrderbookRecord extends Record { + bids: Array<{ price_r: {}, price: number, amount: string }> + asks: Array<{ price_r: {}, price: number, amount: string }> + selling: Asset + buying: Asset +} + +export interface PaymentPathRecord extends Record { + path: Array<{ + asset_code: string + asset_issuer: string + asset_type: string + }> + source_amount: string + source_asset_type: string + source_asset_code: string + source_asset_issuer: string + destination_amount: string + destination_asset_type: string + destination_asset_code: string + destination_asset_issuer: string +} + +export interface TradeRecord extends Record { + id: string + paging_token: string + ledger_close_time: string + base_account: string + base_amount: string + base_asset_type: string + base_asset_code: string + base_asset_issuer: string + counter_account: string + counter_amount: string + counter_asset_type: string + counter_asset_code: string + counter_asset_issuer: string + base_is_seller: boolean + + base: CallFunction + counter: CallFunction + operation: CallFunction +} + +export interface TradeAggregationRecord extends Record { + timestamp: string + trade_count: number + base_volume: string + counter_volume: string + avg: string + high: string + low: string + open: string + close: string +} + +export interface TransactionRecord extends Record { + id: string + paging_token: string + hash: string + ledger_attr: number + created_at: string + max_fee: number + fee_paid: number + operation_count: number + result_code: number + result_code_s: string + source_account: string + source_account_sequence: string + envelope_xdr: string + result_xdr: string + result_meta_xdr: string + memo: string + + account: CallFunction + effects: CallCollectionFunction + ledger: CallFunction + operations: CallCollectionFunction + precedes: CallFunction + self: CallFunction + succeeds: CallFunction +} + +export class AccountCallBuilder extends CallBuilder { + accountId(id: string): this +} +export class AccountResponse implements AccountRecord { + _links: { [key: string]: { href: string } } + id: string + paging_token: string + account_id: string + sequence: number + subentry_count: number + thresholds: { + low_threshold: number + med_threshold: number + high_threshold: number + } + flags: { + auth_required: boolean + auth_revocable: boolean + } + balances: Array< + { + balance: string + asset_type: 'native' + } | + { + balance: string + limit: string + asset_type: 'credit_alphanum4' | 'credit_alphanum12' + asset_code: string + asset_issuer: string + } + > + signers: Array< + { + _key: string + weight: number + } + > + data: { + [key: string]: string + } + + effects: CallCollectionFunction + offers: CallCollectionFunction + operations: CallCollectionFunction + payments: CallCollectionFunction + trades: CallCollectionFunction + constructor(response: AccountRecord) + accountId(): string + sequenceNumber(): string + incrementSequenceNumber(): void +} + +export class Asset { + static native(): Asset + constructor(code: string, issuer: string) + + getCode(): string + getIssuer(): string + getAssetType(): 'native' | 'credit_alphanum4' | 'credit_alphanum12' + isNative(): boolean + equals(other: Asset): boolean + + code: string + issuer: string +} + +export class AssetsCallBuilder extends CallBuilder { + forCode(value: string): this + forIssuer(value: string): this +} + +export namespace Config { + function setAllowHttp(allow: boolean): void + function isAllowHttp(): boolean + function setDefault(): void +} + +export class EffectCallBuilder extends CallBuilder { + forAccount(accountId: string): this + forLedger(sequence: string): this + forOperation(operationId: number): this + forTransaction(transactionId: string): this +} + +export interface FederationRecord { + account_id: string + memo_type?: string + memo?: string +} + +export interface FederationOptions { + allowHttp: boolean +} +export class FederationServer { + static createForDomain(domain: string, options?: FederationOptions): Promise + static resolve(value: string, options?: FederationOptions): Promise + + constructor(serverURL: string, domain: string, options?: FederationOptions) + resolveAccountId(account: string): Promise + resolveAddress(address: string): Promise + resolveTransactionId(transactionId: string): Promise +} + +export class LedgerCallBuilder extends CallBuilder { } + +export class Memo { + static fromXDRObject(memo: xdr.Memo): Memo + static hash(hash: string): Memo + static id(id: string): Memo + static none(): Memo + static return(hash: string): Memo + static text(text: string): Memo + + constructor(type: 'MemoNone') + constructor(type: 'MemoID' | 'MemoText', value: string) + constructor(type: 'MemoHash' | 'MemoReturn', value: Buffer) + + type: 'MemoNone' | 'MemoID' | 'MemoText' | 'MemoHash' | 'MemoReturn' + value: null | string | Buffer + + toXDRObject(): xdr.Memo +} + +export enum Networks { + PUBLIC = 'Public Global Stellar Network ; September 2015', + TESTNET = 'Test SDF Network ; September 2015', +} + +export class Network { + static use(network: Network): void + static usePublicNetwork(): void + static useTestNetwork(): void + static current(): Network + + constructor(passphrase: string) + + networkPassphrase(): string + networkId(): string +} + +export class OfferCallBuilder extends CallBuilder { } + +export type TransactionOperation = + Operation.CreateAccount + | Operation.Payment + | Operation.PathPayment + | Operation.CreatePassiveOffer + | Operation.ManageOffer + | Operation.SetOptions + | Operation.ChangeTrust + | Operation.AllowTrust + | Operation.AccountMerge + | Operation.Inflation + | Operation.ManageData + +export enum OperationType { + createAccount = 'createAccount', + payment = 'payment', + pathPayment = 'pathPayment', + createPassiveOffer = 'createPassiveOffer', + manageOffer = 'manageOffer', + setOptions = 'setOptions', + changeTrust = 'changeTrust', + allowTrust = 'allowTrust', + accountMerge = 'accountMerge', + inflation = 'inflation', + manageData = 'manageData', +} + +export namespace Operation { + interface Operation { + type: OperationType + source: string | null + } + interface AccountMerge extends Operation { + type: OperationType.accountMerge + destination: string + } + interface AccountMergeOptions { + destination: string + source?: string + } + function accountMerge(options: AccountMergeOptions): xdr.Operation + + interface AllowTrust extends Operation { + type: OperationType.allowTrust + trustor: string + assetCode: string + authorize: boolean + } + interface AllowTrustOptions { + trustor: string + assetCode: string + authorize: boolean + source?: string + } + function allowTrust(options: AllowTrustOptions): xdr.Operation + + interface ChangeTrust extends Operation { + type: OperationType.changeTrust + line: Asset + limit: string | number + } + interface ChangeTrustOptions { + asset: Asset + limit: string + source?: string + } + function changeTrust(options: ChangeTrustOptions): xdr.Operation + + interface CreateAccount extends Operation { + type: OperationType.createAccount + source: string + destination: string + startingBalance: string | number + } + interface CreateAccountOptions { + destination: string + startingBalance: string + source?: string + } + function createAccount(options: CreateAccountOptions): xdr.Operation + + interface CreatePassiveOffer extends Operation { + type: OperationType.createPassiveOffer + selling: Asset + buying: Asset + amount: string | number + price: string | number + } + interface CreatePassiveOfferOptions { + selling: Asset + buying: Asset + amount: string + price: number | string | object + source?: string + } + function createPassiveOffer(options: CreatePassiveOfferOptions): xdr.Operation + + interface Inflation extends Operation { + type: OperationType.inflation + } + function inflation(options: { source?: string }): xdr.Operation + + interface ManageData extends Operation { + type: OperationType.manageData + name: string + value: string + } + interface ManageDataOptions { + name: string + value: string | Buffer + source?: string + } + function manageData(options: ManageDataOptions): xdr.Operation + + interface ManageOffer extends Operation { + type: OperationType.manageOffer + selling: Asset + buying: Asset + amount: string | number + price: string | number + offerId: string + } + interface ManageOfferOptions extends CreatePassiveOfferOptions { + offerId: number | string + } + function manageOffer(options: ManageOfferOptions): xdr.Operation + + interface PathPayment extends Operation { + type: OperationType.pathPayment + sendAsset: Asset + sendMax: string | number + destination: string + destAsset: Asset + destAmount: string | number + path: Asset[] + } + interface PathPaymentOptions { + sendAsset: Asset + sendMax: string + destination: string + destAsset: Asset + destAmount: string + path: Asset[] + source?: string + } + function pathPayment(options: PathPaymentOptions): xdr.Operation + + interface Payment extends Operation { + type: OperationType.payment + destination: string + asset: Asset + amount: string | number + } + interface PaymentOptions { + destination: string + asset: Asset + amount: string + source?: string + } + function payment(options: PaymentOptions): xdr.Operation + + /* + * Required = 1 << 0 + * Revocable = 1 << 1 + * Immutable = 1 << 2 + */ + enum AuthFlags { + Required = 1, + Revocable = 2, + Immutable = 4, + } + interface Signer { + ed25519PublicKey?: string + sha256Hash?: Buffer | string + preAuthTx?: Buffer | string + weight?: number | string + } + interface SetOptions extends Operation { + type: OperationType.setOptions + inflationDest?: string + clearFlags?: AuthFlags + setFlags?: AuthFlags + masterWeight?: number | string + lowThreshold?: number | string + medThreshold?: number | string + highThreshold?: number | string + homeDomain?: string + signer?: Signer + } + interface SetOptionsOptions { + inflationDest?: string + clearFlags?: AuthFlags + setFlags?: AuthFlags + masterWeight?: number | string + lowThreshold?: number | string + medThreshold?: number | string + highThreshold?: number | string + signer?: Signer + homeDomain?: string + source?: string + } + function setOptions(options: SetOptionsOptions): xdr.Operation + + function fromXDRObject(xdrOperation: xdr.Operation): T +} + +export class OperationCallBuilder extends CallBuilder { } +export class OrderbookCallBuilder extends CallBuilder { } +export class PathCallBuilder extends CallBuilder { } +export class PaymentCallBuilder extends CallBuilder { } + +export class Server { + constructor(serverURL: string, options?: { allowHttp: boolean }) + accounts(): AccountCallBuilder + assets(): AssetsCallBuilder + effects(): EffectCallBuilder + ledgers(): LedgerCallBuilder + loadAccount(accountId: string): Promise + offers(resource: string, ...parameters: string[]): OfferCallBuilder + operations(): OperationCallBuilder + orderbook(selling: Asset, buying: Asset): OrderbookCallBuilder + paths( + source: string, + destination: string, + destinationAsset: Asset, + destinationAmount: string, + ): PathCallBuilder + payments(): PaymentCallBuilder + submitTransaction(transaction: Transaction): Promise + tradeAggregation( + base: Asset, + counter: Asset, + startTime: Date, + endTime: Date, + resolution: Date, + ): TradeAggregationCallBuilder + trades(): TradesCallBuilder + transactions(): TransactionCallBuilder +} + +export namespace StrKey { + function encodeEd25519PublicKey(data: Buffer): string + function decodeEd25519PublicKey(data: string): Buffer + function isValidEd25519PublicKey(Key: string): boolean + + function encodeEd25519SecretSeed(data: Buffer): string + function decodeEd25519SecretSeed(data: string): Buffer + function isValidEd25519SecretSeed(seed: string): boolean + + function encodePreAuthTx(data: Buffer): string + function decodePreAuthTx(data: string): Buffer + + function encodeSha256Hash(data: Buffer): string + function decodeSha256Hash(data: string): Buffer +} + +export class TradeAggregationCallBuilder extends CallBuilder { } +export class TradesCallBuilder extends CallBuilder { + forAssetPair(base: Asset, counter: Asset): this + forOffer(offerId: string): this +} + +export class Transaction { + constructor(envelope: string | xdr.TransactionEnvelope) + hash(): Buffer + sign(...keypairs: Keypair[]): void + signatureBase(): Buffer + signHashX(preimage: Buffer | string): void + toEnvelope(): xdr.TransactionEnvelope + + operations: TransactionOperation[] + sequence: number + fee: number + source: string + memo: Memo +} + +export class TransactionBuilder { + constructor(sourceAccount: Account, options?: TransactionBuilder.TransactionBuilderOptions) + addOperation(operation: xdr.Operation): this + addMemo(memo: Memo): this + build(): Transaction +} + +export namespace TransactionBuilder { + interface TransactionBuilderOptions { + fee?: number + timebounds?: { + minTime?: number | string + maxTime?: number | string + } + memo?: Memo + } +} + +export class TransactionCallBuilder extends CallBuilder { + transaction(transactionId: string): this + forAccount(accountId: string): this + forLedger(sequence: string | number): this +} + +export class Keypair { + static fromRawEd25519Seed(secretSeed: Buffer): Keypair + static fromSecret(secretKey: string): Keypair + static master(): Keypair + static fromPublicKey(publicKey: string): Keypair + static random(): Keypair + + constructor(keys: { type: 'ed25519', secretKey: string } | { type: 'ed25519', Key: string }) + + publicKey(): string + secret(): string + rawSecretKey(): Buffer + canSign(): boolean + sign(data: Buffer): Buffer + verify(data: Buffer, signature: Buffer): boolean +} + +export namespace xdr { + class XDRStruct { + toXDR(): Buffer + } + class Operation extends XDRStruct { } + class Asset extends XDRStruct { } + class Memo extends XDRStruct { } + class TransactionEnvelope extends XDRStruct { } +} diff --git a/types/stellar-sdk/stellar-sdk-tests.ts b/types/stellar-sdk/stellar-sdk-tests.ts new file mode 100644 index 0000000000..c403b6bc56 --- /dev/null +++ b/types/stellar-sdk/stellar-sdk-tests.ts @@ -0,0 +1,9 @@ +import * as StellarSdk from 'stellar-sdk' + +const sourceKey = StellarSdk.Keypair.random() // $ExpectType Keypair +const destKey = StellarSdk.Keypair.random() +const account = new StellarSdk.Account(sourceKey.publicKey(), 1) +const transaction = new StellarSdk.TransactionBuilder(account) + .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()})) + .build() // $ExpectType () => Transaction +transaction // $ExpectType Transaction diff --git a/types/stellar-sdk/tsconfig.json b/types/stellar-sdk/tsconfig.json new file mode 100644 index 0000000000..12dfa57fa0 --- /dev/null +++ b/types/stellar-sdk/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "stellar-sdk-tests.ts" + ] +} diff --git a/types/stellar-sdk/tslint.json b/types/stellar-sdk/tslint.json new file mode 100644 index 0000000000..69ba71b727 --- /dev/null +++ b/types/stellar-sdk/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "quotemark": [true, "single"], + "semicolon": [true, "never"] + } +} From 0c8427bca4f4452717f4ff02a6477181af31e825 Mon Sep 17 00:00:00 2001 From: Carl Foster Date: Sat, 10 Mar 2018 13:05:28 +1000 Subject: [PATCH 18/22] Update tslint rules --- types/stellar-sdk/index.d.ts | 920 ++++++++++++------------- types/stellar-sdk/stellar-sdk-tests.ts | 12 +- types/stellar-sdk/tslint.json | 6 +- 3 files changed, 467 insertions(+), 471 deletions(-) diff --git a/types/stellar-sdk/index.d.ts b/types/stellar-sdk/index.d.ts index 307c6b44af..e4a6e6a06f 100644 --- a/types/stellar-sdk/index.d.ts +++ b/types/stellar-sdk/index.d.ts @@ -8,35 +8,35 @@ export class Account { constructor(accountId: string, sequence: string | number) - accountId(): string - sequenceNumber(): string - incrementSequenceNumber(): void + accountId(): string; + sequenceNumber(): string; + incrementSequenceNumber(): void; } export class CallBuilder { constructor(serverUrl: string) - call(): Promise> - cursor(cursor: string): this - limit(limit: number): this - order(direction: 'asc' | 'desc'): this - stream(options?: { onmessage?: () => void, onerror?: () => void }): () => void + call(): Promise>; + cursor(cursor: string): this; + limit(limit: number): this; + order(direction: 'asc' | 'desc'): this; + stream(options?: { onmessage?: () => void, onerror?: () => void }): () => void; } export interface CollectionPage { - records: T[], - next: () => Promise>, - prev: () => Promise>, + records: T[]; + next: () => Promise>; + prev: () => Promise>; } export interface Record { _links: { [key: string]: RecordLink - } + }; } export interface RecordLink { - href: string - templated?: boolean + href: string; + templated?: boolean; } /* Due to a bug with the recursive function requests */ @@ -45,37 +45,37 @@ export interface CollectionRecord { next: RecordLink prev: RecordLink self: RecordLink - } + }; _embedded: { records: T[] - } + }; } export interface CallFunctionTemplateOptions { - cursor?: string | number - limit?: number - order?: 'asc' | 'desc' + cursor?: string | number; + limit?: number; + order?: 'asc' | 'desc'; } -export type CallFunction = () => Promise +export type CallFunction = () => Promise; export type CallCollectionFunction = - (options?: CallFunctionTemplateOptions) => Promise> + (options?: CallFunctionTemplateOptions) => Promise>; export interface AccountRecord extends Record { - id: string - paging_token: string - account_id: string - sequence: number - subentry_count: number + id: string; + paging_token: string; + account_id: string; + sequence: number; + subentry_count: number; thresholds: { low_threshold: number med_threshold: number high_threshold: number - } + }; flags: { auth_required: boolean auth_revocable: boolean - } + }; balances: Array< { balance: string @@ -88,211 +88,211 @@ export interface AccountRecord extends Record { asset_code: string asset_issuer: string } - > + >; signers: Array< { _key: string weight: number } - > + >; data: { [key: string]: string - } + }; - effects: CallCollectionFunction - offers: CallCollectionFunction - operations: CallCollectionFunction - payments: CallCollectionFunction - trades: CallCollectionFunction + effects: CallCollectionFunction; + offers: CallCollectionFunction; + operations: CallCollectionFunction; + payments: CallCollectionFunction; + trades: CallCollectionFunction; } export interface AssetRecord extends Record { - asset_type: 'credit_alphanum4' | 'credit_alphanum12' - asset_code: string - asset_issuer: string - paging_token: string - amount: string - num_accounts: number + asset_type: 'credit_alphanum4' | 'credit_alphanum12'; + asset_code: string; + asset_issuer: string; + paging_token: string; + amount: string; + num_accounts: number; flags: { auth_required: boolean auth_revocable: boolean - } + }; } export interface EffectRecord extends Record { - account: string - paging_token: string - starting_balance: string - type_i: string - type: string + account: string; + paging_token: string; + starting_balance: string; + type_i: string; + type: string; - operation?: CallFunction - precedes?: CallFunction - succeeds?: CallFunction + operation?: CallFunction; + precedes?: CallFunction; + succeeds?: CallFunction; } export interface LedgerRecord extends Record { - id: string - paging_token: string - hash: string - prev_hash: string - sequence: number - transaction_count: number - operation_count: number - closed_at: string - total_coins: string - fee_pool: string - base_fee: number - base_reserve: string - max_tx_set_size: number - protocol_version: number - header_xdr: string - base_fee_in_stroops: number - base_reserve_in_stroops: number + id: string; + paging_token: string; + hash: string; + prev_hash: string; + sequence: number; + transaction_count: number; + operation_count: number; + closed_at: string; + total_coins: string; + fee_pool: string; + base_fee: number; + base_reserve: string; + max_tx_set_size: number; + protocol_version: number; + header_xdr: string; + base_fee_in_stroops: number; + base_reserve_in_stroops: number; - effects: CallCollectionFunction - operations: CallCollectionFunction - self: CallFunction - transactions: CallCollectionFunction + effects: CallCollectionFunction; + operations: CallCollectionFunction; + self: CallFunction; + transactions: CallCollectionFunction; } export interface OfferRecord extends Record { - id: string - paging_token: string - seller_attr: string - selling: Asset - buying: Asset - amount: string - price_r: { numerator: number, denominator: number } - price: string + id: string; + paging_token: string; + seller_attr: string; + selling: Asset; + buying: Asset; + amount: string; + price_r: { numerator: number, denominator: number }; + price: string; - seller?: CallFunction + seller?: CallFunction; } export interface BaseOperationRecord extends Record { - id: string - paging_token: string - type: string - type_i: number + id: string; + paging_token: string; + type: string; + type_i: number; - self: CallFunction - succeeds: CallFunction - precedes: CallFunction - effects: CallCollectionFunction - transaction: CallFunction + self: CallFunction; + succeeds: CallFunction; + precedes: CallFunction; + effects: CallCollectionFunction; + transaction: CallFunction; } export interface CreateAccountOperationRecord extends BaseOperationRecord { - type: 'create_account' - account: string - funder: string - starting_balance: string + type: 'create_account'; + account: string; + funder: string; + starting_balance: string; } export interface PaymentOperationRecord extends BaseOperationRecord { - type: 'payment' - from: string - to: string - asset_type: string - asset_code?: string - asset_issuer?: string - amount: string + type: 'payment'; + from: string; + to: string; + asset_type: string; + asset_code?: string; + asset_issuer?: string; + amount: string; - sender: CallFunction - receiver: CallFunction + sender: CallFunction; + receiver: CallFunction; } export interface PathPaymentOperationRecord extends BaseOperationRecord { - type: 'path_payment' - from: string - to: string - asset_code?: string - asset_issuer?: string - asset_type: string - amount: string - source_asset_code?: string - source_asset_issuer?: string - source_asset_type: string - source_max: string - source_amount: string + type: 'path_payment'; + from: string; + to: string; + asset_code?: string; + asset_issuer?: string; + asset_type: string; + amount: string; + source_asset_code?: string; + source_asset_issuer?: string; + source_asset_type: string; + source_max: string; + source_amount: string; } export interface ManageOfferOperationRecord extends BaseOperationRecord { - type: 'manage_offer' - offer_id: number - amount: string - buying_asset_code?: string - buying_asset_issuer?: string - buying_asset_type: string - price: string - price_r: { numerator: number, denominator: number } - selling_asset_code?: string - selling_asset_issuer?: string - selling_asset_type: string + type: 'manage_offer'; + offer_id: number; + amount: string; + buying_asset_code?: string; + buying_asset_issuer?: string; + buying_asset_type: string; + price: string; + price_r: { numerator: number, denominator: number }; + selling_asset_code?: string; + selling_asset_issuer?: string; + selling_asset_type: string; } export interface PassiveOfferOperationRecord extends BaseOperationRecord { - type: 'create_passive_offer' - offer_id: number - amount: string - buying_asset_code?: string - buying_asset_issuer?: string - buying_asset_type: string - price: string - price_r: { numerator: number, denominator: number } - selling_asset_code?: string - selling_asset_issuer?: string - selling_asset_type: string + type: 'create_passive_offer'; + offer_id: number; + amount: string; + buying_asset_code?: string; + buying_asset_issuer?: string; + buying_asset_type: string; + price: string; + price_r: { numerator: number, denominator: number }; + selling_asset_code?: string; + selling_asset_issuer?: string; + selling_asset_type: string; } export interface SetOptionsOperationRecord extends BaseOperationRecord { - type: 'set_options' - signer_key?: string - signer_weight?: number - master_key_weight?: number - low_threshold?: number - med_threshold?: number - high_threshold?: number - home_domain?: string - set_flags: Array<(1 | 2)> - set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')> - clear_flags: Array<(1 | 2)> - clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')> + type: 'set_options'; + signer_key?: string; + signer_weight?: number; + master_key_weight?: number; + low_threshold?: number; + med_threshold?: number; + high_threshold?: number; + home_domain?: string; + set_flags: Array<(1 | 2)>; + set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; + clear_flags: Array<(1 | 2)>; + clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; } export interface ChangeTrustOperationRecord extends BaseOperationRecord { - type: 'change_trust' - asset_code: string - asset_issuer: string - asset_type: string - trustee: string - trustor: string - limit: string + type: 'change_trust'; + asset_code: string; + asset_issuer: string; + asset_type: string; + trustee: string; + trustor: string; + limit: string; } export interface AllowTrustOperationRecord extends BaseOperationRecord { - type: 'allow_trust' - asset_code: string - asset_issuer: string - asset_type: string - authorize: boolean - trustee: string - trustor: string + type: 'allow_trust'; + asset_code: string; + asset_issuer: string; + asset_type: string; + authorize: boolean; + trustee: string; + trustor: string; } export interface AccountMergeOperationRecord extends BaseOperationRecord { - type: 'account_merge' - into: string + type: 'account_merge'; + into: string; } export interface InflationOperationRecord extends BaseOperationRecord { - type: 'inflation' + type: 'inflation'; } export interface ManageDataOperationRecord extends BaseOperationRecord { - type: 'manage_data' - name: string - value: string + type: 'manage_data'; + name: string; + value: string; } export type OperationRecord = CreateAccountOperationRecord @@ -305,13 +305,13 @@ export type OperationRecord = CreateAccountOperationRecord | AllowTrustOperationRecord | AccountMergeOperationRecord | InflationOperationRecord - | ManageDataOperationRecord + | ManageDataOperationRecord; export interface OrderbookRecord extends Record { - bids: Array<{ price_r: {}, price: number, amount: string }> - asks: Array<{ price_r: {}, price: number, amount: string }> - selling: Asset - buying: Asset + bids: Array<{ price_r: {}, price: number, amount: string }>; + asks: Array<{ price_r: {}, price: number, amount: string }>; + selling: Asset; + buying: Asset; } export interface PaymentPathRecord extends Record { @@ -319,96 +319,96 @@ export interface PaymentPathRecord extends Record { asset_code: string asset_issuer: string asset_type: string - }> - source_amount: string - source_asset_type: string - source_asset_code: string - source_asset_issuer: string - destination_amount: string - destination_asset_type: string - destination_asset_code: string - destination_asset_issuer: string + }>; + source_amount: string; + source_asset_type: string; + source_asset_code: string; + source_asset_issuer: string; + destination_amount: string; + destination_asset_type: string; + destination_asset_code: string; + destination_asset_issuer: string; } export interface TradeRecord extends Record { - id: string - paging_token: string - ledger_close_time: string - base_account: string - base_amount: string - base_asset_type: string - base_asset_code: string - base_asset_issuer: string - counter_account: string - counter_amount: string - counter_asset_type: string - counter_asset_code: string - counter_asset_issuer: string - base_is_seller: boolean + id: string; + paging_token: string; + ledger_close_time: string; + base_account: string; + base_amount: string; + base_asset_type: string; + base_asset_code: string; + base_asset_issuer: string; + counter_account: string; + counter_amount: string; + counter_asset_type: string; + counter_asset_code: string; + counter_asset_issuer: string; + base_is_seller: boolean; - base: CallFunction - counter: CallFunction - operation: CallFunction + base: CallFunction; + counter: CallFunction; + operation: CallFunction; } export interface TradeAggregationRecord extends Record { - timestamp: string - trade_count: number - base_volume: string - counter_volume: string - avg: string - high: string - low: string - open: string - close: string + timestamp: string; + trade_count: number; + base_volume: string; + counter_volume: string; + avg: string; + high: string; + low: string; + open: string; + close: string; } export interface TransactionRecord extends Record { - id: string - paging_token: string - hash: string - ledger_attr: number - created_at: string - max_fee: number - fee_paid: number - operation_count: number - result_code: number - result_code_s: string - source_account: string - source_account_sequence: string - envelope_xdr: string - result_xdr: string - result_meta_xdr: string - memo: string + id: string; + paging_token: string; + hash: string; + ledger_attr: number; + created_at: string; + max_fee: number; + fee_paid: number; + operation_count: number; + result_code: number; + result_code_s: string; + source_account: string; + source_account_sequence: string; + envelope_xdr: string; + result_xdr: string; + result_meta_xdr: string; + memo: string; - account: CallFunction - effects: CallCollectionFunction - ledger: CallFunction - operations: CallCollectionFunction - precedes: CallFunction - self: CallFunction - succeeds: CallFunction + account: CallFunction; + effects: CallCollectionFunction; + ledger: CallFunction; + operations: CallCollectionFunction; + precedes: CallFunction; + self: CallFunction; + succeeds: CallFunction; } export class AccountCallBuilder extends CallBuilder { - accountId(id: string): this + accountId(id: string): this; } export class AccountResponse implements AccountRecord { - _links: { [key: string]: { href: string } } - id: string - paging_token: string - account_id: string - sequence: number - subentry_count: number + _links: { [key: string]: { href: string } }; + id: string; + paging_token: string; + account_id: string; + sequence: number; + subentry_count: number; thresholds: { low_threshold: number med_threshold: number high_threshold: number - } + }; flags: { auth_required: boolean auth_revocable: boolean - } + }; balances: Array< { balance: string @@ -421,97 +421,97 @@ export class AccountResponse implements AccountRecord { asset_code: string asset_issuer: string } - > + >; signers: Array< { _key: string weight: number } - > + >; data: { [key: string]: string - } + }; - effects: CallCollectionFunction - offers: CallCollectionFunction - operations: CallCollectionFunction - payments: CallCollectionFunction - trades: CallCollectionFunction + effects: CallCollectionFunction; + offers: CallCollectionFunction; + operations: CallCollectionFunction; + payments: CallCollectionFunction; + trades: CallCollectionFunction; constructor(response: AccountRecord) - accountId(): string - sequenceNumber(): string - incrementSequenceNumber(): void + accountId(): string; + sequenceNumber(): string; + incrementSequenceNumber(): void; } export class Asset { - static native(): Asset + static native(): Asset; constructor(code: string, issuer: string) - getCode(): string - getIssuer(): string - getAssetType(): 'native' | 'credit_alphanum4' | 'credit_alphanum12' - isNative(): boolean - equals(other: Asset): boolean + getCode(): string; + getIssuer(): string; + getAssetType(): 'native' | 'credit_alphanum4' | 'credit_alphanum12'; + isNative(): boolean; + equals(other: Asset): boolean; - code: string - issuer: string + code: string; + issuer: string; } export class AssetsCallBuilder extends CallBuilder { - forCode(value: string): this - forIssuer(value: string): this + forCode(value: string): this; + forIssuer(value: string): this; } export namespace Config { - function setAllowHttp(allow: boolean): void - function isAllowHttp(): boolean - function setDefault(): void + function setAllowHttp(allow: boolean): void; + function isAllowHttp(): boolean; + function setDefault(): void; } export class EffectCallBuilder extends CallBuilder { - forAccount(accountId: string): this - forLedger(sequence: string): this - forOperation(operationId: number): this - forTransaction(transactionId: string): this + forAccount(accountId: string): this; + forLedger(sequence: string): this; + forOperation(operationId: number): this; + forTransaction(transactionId: string): this; } export interface FederationRecord { - account_id: string - memo_type?: string - memo?: string + account_id: string; + memo_type?: string; + memo?: string; } export interface FederationOptions { - allowHttp: boolean + allowHttp: boolean; } export class FederationServer { - static createForDomain(domain: string, options?: FederationOptions): Promise - static resolve(value: string, options?: FederationOptions): Promise + static createForDomain(domain: string, options?: FederationOptions): Promise; + static resolve(value: string, options?: FederationOptions): Promise; constructor(serverURL: string, domain: string, options?: FederationOptions) - resolveAccountId(account: string): Promise - resolveAddress(address: string): Promise - resolveTransactionId(transactionId: string): Promise + resolveAccountId(account: string): Promise; + resolveAddress(address: string): Promise; + resolveTransactionId(transactionId: string): Promise; } export class LedgerCallBuilder extends CallBuilder { } export class Memo { - static fromXDRObject(memo: xdr.Memo): Memo - static hash(hash: string): Memo - static id(id: string): Memo - static none(): Memo - static return(hash: string): Memo - static text(text: string): Memo + static fromXDRObject(memo: xdr.Memo): Memo; + static hash(hash: string): Memo; + static id(id: string): Memo; + static none(): Memo; + static return(hash: string): Memo; + static text(text: string): Memo; constructor(type: 'MemoNone') constructor(type: 'MemoID' | 'MemoText', value: string) constructor(type: 'MemoHash' | 'MemoReturn', value: Buffer) - type: 'MemoNone' | 'MemoID' | 'MemoText' | 'MemoHash' | 'MemoReturn' - value: null | string | Buffer + type: 'MemoNone' | 'MemoID' | 'MemoText' | 'MemoHash' | 'MemoReturn'; + value: null | string | Buffer; - toXDRObject(): xdr.Memo + toXDRObject(): xdr.Memo; } export enum Networks { @@ -520,15 +520,15 @@ export enum Networks { } export class Network { - static use(network: Network): void - static usePublicNetwork(): void - static useTestNetwork(): void - static current(): Network + static use(network: Network): void; + static usePublicNetwork(): void; + static useTestNetwork(): void; + static current(): Network; constructor(passphrase: string) - networkPassphrase(): string - networkId(): string + networkPassphrase(): string; + networkId(): string; } export class OfferCallBuilder extends CallBuilder { } @@ -544,7 +544,7 @@ export type TransactionOperation = | Operation.AllowTrust | Operation.AccountMerge | Operation.Inflation - | Operation.ManageData + | Operation.ManageData; export enum OperationType { createAccount = 'createAccount', @@ -562,137 +562,137 @@ export enum OperationType { export namespace Operation { interface Operation { - type: OperationType - source: string | null + type: OperationType; + source: string | null; } interface AccountMerge extends Operation { - type: OperationType.accountMerge - destination: string + type: OperationType.accountMerge; + destination: string; } interface AccountMergeOptions { - destination: string - source?: string + destination: string; + source?: string; } - function accountMerge(options: AccountMergeOptions): xdr.Operation + function accountMerge(options: AccountMergeOptions): xdr.Operation; interface AllowTrust extends Operation { - type: OperationType.allowTrust - trustor: string - assetCode: string - authorize: boolean + type: OperationType.allowTrust; + trustor: string; + assetCode: string; + authorize: boolean; } interface AllowTrustOptions { - trustor: string - assetCode: string - authorize: boolean - source?: string + trustor: string; + assetCode: string; + authorize: boolean; + source?: string; } - function allowTrust(options: AllowTrustOptions): xdr.Operation + function allowTrust(options: AllowTrustOptions): xdr.Operation; interface ChangeTrust extends Operation { - type: OperationType.changeTrust - line: Asset - limit: string | number + type: OperationType.changeTrust; + line: Asset; + limit: string | number; } interface ChangeTrustOptions { - asset: Asset - limit: string - source?: string + asset: Asset; + limit: string; + source?: string; } - function changeTrust(options: ChangeTrustOptions): xdr.Operation + function changeTrust(options: ChangeTrustOptions): xdr.Operation; interface CreateAccount extends Operation { - type: OperationType.createAccount - source: string - destination: string - startingBalance: string | number + type: OperationType.createAccount; + source: string; + destination: string; + startingBalance: string | number; } interface CreateAccountOptions { - destination: string - startingBalance: string - source?: string + destination: string; + startingBalance: string; + source?: string; } - function createAccount(options: CreateAccountOptions): xdr.Operation + function createAccount(options: CreateAccountOptions): xdr.Operation; interface CreatePassiveOffer extends Operation { - type: OperationType.createPassiveOffer - selling: Asset - buying: Asset - amount: string | number - price: string | number + type: OperationType.createPassiveOffer; + selling: Asset; + buying: Asset; + amount: string | number; + price: string | number; } interface CreatePassiveOfferOptions { - selling: Asset - buying: Asset - amount: string - price: number | string | object - source?: string + selling: Asset; + buying: Asset; + amount: string; + price: number | string | object; + source?: string; } - function createPassiveOffer(options: CreatePassiveOfferOptions): xdr.Operation + function createPassiveOffer(options: CreatePassiveOfferOptions): xdr.Operation; interface Inflation extends Operation { - type: OperationType.inflation + type: OperationType.inflation; } - function inflation(options: { source?: string }): xdr.Operation + function inflation(options: { source?: string }): xdr.Operation; interface ManageData extends Operation { - type: OperationType.manageData - name: string - value: string + type: OperationType.manageData; + name: string; + value: string; } interface ManageDataOptions { - name: string - value: string | Buffer - source?: string + name: string; + value: string | Buffer; + source?: string; } - function manageData(options: ManageDataOptions): xdr.Operation + function manageData(options: ManageDataOptions): xdr.Operation; interface ManageOffer extends Operation { - type: OperationType.manageOffer - selling: Asset - buying: Asset - amount: string | number - price: string | number - offerId: string + type: OperationType.manageOffer; + selling: Asset; + buying: Asset; + amount: string | number; + price: string | number; + offerId: string; } interface ManageOfferOptions extends CreatePassiveOfferOptions { - offerId: number | string + offerId: number | string; } - function manageOffer(options: ManageOfferOptions): xdr.Operation + function manageOffer(options: ManageOfferOptions): xdr.Operation; interface PathPayment extends Operation { - type: OperationType.pathPayment - sendAsset: Asset - sendMax: string | number - destination: string - destAsset: Asset - destAmount: string | number - path: Asset[] + type: OperationType.pathPayment; + sendAsset: Asset; + sendMax: string | number; + destination: string; + destAsset: Asset; + destAmount: string | number; + path: Asset[]; } interface PathPaymentOptions { - sendAsset: Asset - sendMax: string - destination: string - destAsset: Asset - destAmount: string - path: Asset[] - source?: string + sendAsset: Asset; + sendMax: string; + destination: string; + destAsset: Asset; + destAmount: string; + path: Asset[]; + source?: string; } - function pathPayment(options: PathPaymentOptions): xdr.Operation + function pathPayment(options: PathPaymentOptions): xdr.Operation; interface Payment extends Operation { - type: OperationType.payment - destination: string - asset: Asset - amount: string | number + type: OperationType.payment; + destination: string; + asset: Asset; + amount: string | number; } interface PaymentOptions { - destination: string - asset: Asset - amount: string - source?: string + destination: string; + asset: Asset; + amount: string; + source?: string; } - function payment(options: PaymentOptions): xdr.Operation + function payment(options: PaymentOptions): xdr.Operation; /* * Required = 1 << 0 @@ -705,38 +705,38 @@ export namespace Operation { Immutable = 4, } interface Signer { - ed25519PublicKey?: string - sha256Hash?: Buffer | string - preAuthTx?: Buffer | string - weight?: number | string + ed25519PublicKey?: string; + sha256Hash?: Buffer | string; + preAuthTx?: Buffer | string; + weight?: number | string; } interface SetOptions extends Operation { - type: OperationType.setOptions - inflationDest?: string - clearFlags?: AuthFlags - setFlags?: AuthFlags - masterWeight?: number | string - lowThreshold?: number | string - medThreshold?: number | string - highThreshold?: number | string - homeDomain?: string - signer?: Signer + type: OperationType.setOptions; + inflationDest?: string; + clearFlags?: AuthFlags; + setFlags?: AuthFlags; + masterWeight?: number | string; + lowThreshold?: number | string; + medThreshold?: number | string; + highThreshold?: number | string; + homeDomain?: string; + signer?: Signer; } interface SetOptionsOptions { - inflationDest?: string - clearFlags?: AuthFlags - setFlags?: AuthFlags - masterWeight?: number | string - lowThreshold?: number | string - medThreshold?: number | string - highThreshold?: number | string - signer?: Signer - homeDomain?: string - source?: string + inflationDest?: string; + clearFlags?: AuthFlags; + setFlags?: AuthFlags; + masterWeight?: number | string; + lowThreshold?: number | string; + medThreshold?: number | string; + highThreshold?: number | string; + signer?: Signer; + homeDomain?: string; + source?: string; } - function setOptions(options: SetOptionsOptions): xdr.Operation + function setOptions(options: SetOptionsOptions): xdr.Operation; - function fromXDRObject(xdrOperation: xdr.Operation): T + function fromXDRObject(xdrOperation: xdr.Operation): T; } export class OperationCallBuilder extends CallBuilder { } @@ -746,114 +746,114 @@ export class PaymentCallBuilder extends CallBuilder { } export class Server { constructor(serverURL: string, options?: { allowHttp: boolean }) - accounts(): AccountCallBuilder - assets(): AssetsCallBuilder - effects(): EffectCallBuilder - ledgers(): LedgerCallBuilder - loadAccount(accountId: string): Promise - offers(resource: string, ...parameters: string[]): OfferCallBuilder - operations(): OperationCallBuilder - orderbook(selling: Asset, buying: Asset): OrderbookCallBuilder + accounts(): AccountCallBuilder; + assets(): AssetsCallBuilder; + effects(): EffectCallBuilder; + ledgers(): LedgerCallBuilder; + loadAccount(accountId: string): Promise; + offers(resource: string, ...parameters: string[]): OfferCallBuilder; + operations(): OperationCallBuilder; + orderbook(selling: Asset, buying: Asset): OrderbookCallBuilder; paths( source: string, destination: string, destinationAsset: Asset, destinationAmount: string, - ): PathCallBuilder - payments(): PaymentCallBuilder - submitTransaction(transaction: Transaction): Promise + ): PathCallBuilder; + payments(): PaymentCallBuilder; + submitTransaction(transaction: Transaction): Promise; tradeAggregation( base: Asset, counter: Asset, startTime: Date, endTime: Date, resolution: Date, - ): TradeAggregationCallBuilder - trades(): TradesCallBuilder - transactions(): TransactionCallBuilder + ): TradeAggregationCallBuilder; + trades(): TradesCallBuilder; + transactions(): TransactionCallBuilder; } export namespace StrKey { - function encodeEd25519PublicKey(data: Buffer): string - function decodeEd25519PublicKey(data: string): Buffer - function isValidEd25519PublicKey(Key: string): boolean + function encodeEd25519PublicKey(data: Buffer): string; + function decodeEd25519PublicKey(data: string): Buffer; + function isValidEd25519PublicKey(Key: string): boolean; - function encodeEd25519SecretSeed(data: Buffer): string - function decodeEd25519SecretSeed(data: string): Buffer - function isValidEd25519SecretSeed(seed: string): boolean + function encodeEd25519SecretSeed(data: Buffer): string; + function decodeEd25519SecretSeed(data: string): Buffer; + function isValidEd25519SecretSeed(seed: string): boolean; - function encodePreAuthTx(data: Buffer): string - function decodePreAuthTx(data: string): Buffer + function encodePreAuthTx(data: Buffer): string; + function decodePreAuthTx(data: string): Buffer; - function encodeSha256Hash(data: Buffer): string - function decodeSha256Hash(data: string): Buffer + function encodeSha256Hash(data: Buffer): string; + function decodeSha256Hash(data: string): Buffer; } export class TradeAggregationCallBuilder extends CallBuilder { } export class TradesCallBuilder extends CallBuilder { - forAssetPair(base: Asset, counter: Asset): this - forOffer(offerId: string): this + forAssetPair(base: Asset, counter: Asset): this; + forOffer(offerId: string): this; } export class Transaction { constructor(envelope: string | xdr.TransactionEnvelope) - hash(): Buffer - sign(...keypairs: Keypair[]): void - signatureBase(): Buffer - signHashX(preimage: Buffer | string): void - toEnvelope(): xdr.TransactionEnvelope + hash(): Buffer; + sign(...keypairs: Keypair[]): void; + signatureBase(): Buffer; + signHashX(preimage: Buffer | string): void; + toEnvelope(): xdr.TransactionEnvelope; - operations: TransactionOperation[] - sequence: number - fee: number - source: string - memo: Memo + operations: TransactionOperation[]; + sequence: number; + fee: number; + source: string; + memo: Memo; } export class TransactionBuilder { constructor(sourceAccount: Account, options?: TransactionBuilder.TransactionBuilderOptions) - addOperation(operation: xdr.Operation): this - addMemo(memo: Memo): this - build(): Transaction + addOperation(operation: xdr.Operation): this; + addMemo(memo: Memo): this; + build(): Transaction; } export namespace TransactionBuilder { interface TransactionBuilderOptions { - fee?: number + fee?: number; timebounds?: { minTime?: number | string maxTime?: number | string - } - memo?: Memo + }; + memo?: Memo; } } export class TransactionCallBuilder extends CallBuilder { - transaction(transactionId: string): this - forAccount(accountId: string): this - forLedger(sequence: string | number): this + transaction(transactionId: string): this; + forAccount(accountId: string): this; + forLedger(sequence: string | number): this; } export class Keypair { - static fromRawEd25519Seed(secretSeed: Buffer): Keypair - static fromSecret(secretKey: string): Keypair - static master(): Keypair - static fromPublicKey(publicKey: string): Keypair - static random(): Keypair + static fromRawEd25519Seed(secretSeed: Buffer): Keypair; + static fromSecret(secretKey: string): Keypair; + static master(): Keypair; + static fromPublicKey(publicKey: string): Keypair; + static random(): Keypair; constructor(keys: { type: 'ed25519', secretKey: string } | { type: 'ed25519', Key: string }) - publicKey(): string - secret(): string - rawSecretKey(): Buffer - canSign(): boolean - sign(data: Buffer): Buffer - verify(data: Buffer, signature: Buffer): boolean + publicKey(): string; + secret(): string; + rawSecretKey(): Buffer; + canSign(): boolean; + sign(data: Buffer): Buffer; + verify(data: Buffer, signature: Buffer): boolean; } export namespace xdr { class XDRStruct { - toXDR(): Buffer + toXDR(): Buffer; } class Operation extends XDRStruct { } class Asset extends XDRStruct { } diff --git a/types/stellar-sdk/stellar-sdk-tests.ts b/types/stellar-sdk/stellar-sdk-tests.ts index c403b6bc56..4bd84ccc33 100644 --- a/types/stellar-sdk/stellar-sdk-tests.ts +++ b/types/stellar-sdk/stellar-sdk-tests.ts @@ -1,9 +1,9 @@ -import * as StellarSdk from 'stellar-sdk' +import * as StellarSdk from 'stellar-sdk'; -const sourceKey = StellarSdk.Keypair.random() // $ExpectType Keypair -const destKey = StellarSdk.Keypair.random() -const account = new StellarSdk.Account(sourceKey.publicKey(), 1) +const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair +const destKey = StellarSdk.Keypair.random(); +const account = new StellarSdk.Account(sourceKey.publicKey(), 1); const transaction = new StellarSdk.TransactionBuilder(account) .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()})) - .build() // $ExpectType () => Transaction -transaction // $ExpectType Transaction + .build(); // $ExpectType () => Transaction +transaction; // $ExpectType Transaction diff --git a/types/stellar-sdk/tslint.json b/types/stellar-sdk/tslint.json index 69ba71b727..f93cf8562a 100644 --- a/types/stellar-sdk/tslint.json +++ b/types/stellar-sdk/tslint.json @@ -1,7 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "quotemark": [true, "single"], - "semicolon": [true, "never"] - } + "extends": "dtslint/dt.json" } From 4d75110d7c886e21565488e6a577933ad644f5a1 Mon Sep 17 00:00:00 2001 From: Ragg Date: Sun, 11 Mar 2018 15:12:29 +0900 Subject: [PATCH 19/22] Enable `esModuleInterop` --- types/dispatchr/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/dispatchr/tsconfig.json b/types/dispatchr/tsconfig.json index 47109880da..e94ec73c3c 100644 --- a/types/dispatchr/tsconfig.json +++ b/types/dispatchr/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, + "esModuleInterop": true, "baseUrl": "../", "typeRoots": [ "../" From 75178d3bdf290a817e997194aff407546a9901a3 Mon Sep 17 00:00:00 2001 From: Nick Whyte Date: Mon, 12 Mar 2018 11:07:34 +1100 Subject: [PATCH 20/22] PR Changes --- types/prismic-dom/index.d.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/types/prismic-dom/index.d.ts b/types/prismic-dom/index.d.ts index 82c766fda6..db3b85d4b8 100644 --- a/types/prismic-dom/index.d.ts +++ b/types/prismic-dom/index.d.ts @@ -3,6 +3,13 @@ // Definitions by: Nick Whyte // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export namespace RichText { - function asHtml(richText: any, linkResolver?: (doc: any) => string): string; +interface RichText { + asHtml(richText: any, linkResolver?: (doc: any) => string): string; } + +export const RichText: RichText; + +declare const PrismicDOM: { + RichText: RichText; +}; +export default PrismicDOM; From 6f0b81e2c509805d1a1348b7513340d1929200b9 Mon Sep 17 00:00:00 2001 From: Nick Whyte Date: Mon, 12 Mar 2018 11:25:31 +1100 Subject: [PATCH 21/22] PR Changes --- types/prismic-dom/index.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/prismic-dom/index.d.ts b/types/prismic-dom/index.d.ts index db3b85d4b8..2849cc7791 100644 --- a/types/prismic-dom/index.d.ts +++ b/types/prismic-dom/index.d.ts @@ -9,7 +9,5 @@ interface RichText { export const RichText: RichText; -declare const PrismicDOM: { - RichText: RichText; -}; -export default PrismicDOM; +declare const _default: { RichText: RichText }; +export default _default; From d06ca98a8d9bd46dfa1a7776096e0de07fa3a64c Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Wed, 14 Mar 2018 09:31:28 +0100 Subject: [PATCH 22/22] Update iban-tests.ts --- types/iban/iban-tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/iban/iban-tests.ts b/types/iban/iban-tests.ts index ac79e97a99..574769c461 100644 --- a/types/iban/iban-tests.ts +++ b/types/iban/iban-tests.ts @@ -39,7 +39,7 @@ function testIsValidBBAN() { */ function testPrintFormat() { var iban: string = 'BE68539007547034'; - var separator: string[] = ['fr']; + var separator: string = ' '; var format: string = IBAN.printFormat(iban, separator); } @@ -48,6 +48,6 @@ function testPrintFormat() { */ function testToBBAN() { var iban: string = 'BE68539007547034'; - var separator: string[] = ['-']; + var separator: string = '-'; var bban: string = IBAN.toBBAN(iban, separator); -} \ No newline at end of file +}