mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
all: standardize API response types
ensures that all API methods return promises, for chaining
This commit is contained in:
parent
6f5663bcd3
commit
57605e9aa4
@ -81,7 +81,7 @@ export default class ChatApi extends BaseApi<StoreState> {
|
||||
* If we don't host the chat, then it just leaves
|
||||
*/
|
||||
delete(path: Path) {
|
||||
this.viewAction({ delete: { 'app-path': path } });
|
||||
return this.viewAction({ delete: { 'app-path': path } });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +157,7 @@ export default class ChatApi extends BaseApi<StoreState> {
|
||||
this.store.state.pendingMessages.set(path, [envelope]);
|
||||
}
|
||||
|
||||
this.store.setState({
|
||||
return this.store.setState({
|
||||
pendingMessages: this.store.state.pendingMessages
|
||||
});
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
addGraph(ship: Patp, name: string, graph: any, mark: any) {
|
||||
this.storeAction({
|
||||
return this.storeAction({
|
||||
'add-graph': {
|
||||
resource: { ship, name },
|
||||
graph,
|
||||
@ -31,7 +31,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
removeGraph(ship: Patp, name: string) {
|
||||
this.storeAction({
|
||||
return this.storeAction({
|
||||
'remove-graph': {
|
||||
resource: { ship, name }
|
||||
}
|
||||
@ -45,7 +45,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
children: { empty: null }
|
||||
};
|
||||
|
||||
this.storeAction({
|
||||
return this.storeAction({
|
||||
'add-nodes': {
|
||||
resource: { ship, name },
|
||||
nodes
|
||||
@ -54,7 +54,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
addNodes(ship: Patp, name: string, nodes: Object) {
|
||||
this.storeAction({
|
||||
return this.storeAction({
|
||||
'add-nodes': {
|
||||
resource: { ship, name },
|
||||
nodes
|
||||
@ -63,7 +63,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
removeNodes(ship: Patp, name: string, indices: string[]) {
|
||||
this.storeAction({
|
||||
return this.storeAction({
|
||||
'remove-nodes': {
|
||||
resource: { ship, name },
|
||||
indices
|
||||
@ -72,7 +72,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getKeys() {
|
||||
this.scry<any>('graph-store', '/keys')
|
||||
return this.scry<any>('graph-store', '/keys')
|
||||
.then((keys) => {
|
||||
this.store.handleEvent({
|
||||
data: keys
|
||||
@ -81,7 +81,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getTags() {
|
||||
this.scry<any>('graph-store', '/tags')
|
||||
return this.scry<any>('graph-store', '/tags')
|
||||
.then((tags) => {
|
||||
this.store.handleEvent({
|
||||
data: tags
|
||||
@ -90,7 +90,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getTagQueries() {
|
||||
this.scry<any>('graph-store', '/tag-queries')
|
||||
return this.scry<any>('graph-store', '/tag-queries')
|
||||
.then((tagQueries) => {
|
||||
this.store.handleEvent({
|
||||
data: tagQueries
|
||||
@ -99,7 +99,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getGraph(ship: string, resource: string) {
|
||||
this.scry<any>('graph-store', `/graph/${ship}/${resource}`)
|
||||
return this.scry<any>('graph-store', `/graph/${ship}/${resource}`)
|
||||
.then((graph) => {
|
||||
this.store.handleEvent({
|
||||
data: graph
|
||||
@ -108,7 +108,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getGraphSubset(ship: string, resource: string, start: string, end: start) {
|
||||
this.scry<any>(
|
||||
return this.scry<any>(
|
||||
'graph-store',
|
||||
`/graph-subset/${ship}/${resource}/${end}/${start}`
|
||||
).then((subset) => {
|
||||
@ -119,7 +119,7 @@ export default class GraphApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
getNode(ship: string, resource: string, index: string) {
|
||||
this.scry<any>(
|
||||
return this.scry<any>(
|
||||
'graph-store',
|
||||
`/node/${ship}/${resource}/${index}`
|
||||
).then((node) => {
|
||||
|
@ -5,31 +5,31 @@ import { StoreState } from '../store/type';
|
||||
export default class LaunchApi extends BaseApi<StoreState> {
|
||||
|
||||
add(name: string, tile = { basic : { title: '', linkedUrl: '', iconUrl: '' }}) {
|
||||
this.launchAction({ add: { name, tile } });
|
||||
return this.launchAction({ add: { name, tile } });
|
||||
}
|
||||
|
||||
remove(name: string) {
|
||||
this.launchAction({ remove: name });
|
||||
return this.launchAction({ remove: name });
|
||||
}
|
||||
|
||||
changeOrder(orderedTiles: string[] = []) {
|
||||
this.launchAction({ 'change-order': orderedTiles });
|
||||
return this.launchAction({ 'change-order': orderedTiles });
|
||||
}
|
||||
|
||||
changeFirstTime(firstTime = true) {
|
||||
this.launchAction({ 'change-first-time': firstTime });
|
||||
return this.launchAction({ 'change-first-time': firstTime });
|
||||
}
|
||||
|
||||
changeIsShown(name: string, isShown = true) {
|
||||
this.launchAction({ 'change-is-shown': { name, isShown }});
|
||||
return this.launchAction({ 'change-is-shown': { name, isShown }});
|
||||
}
|
||||
|
||||
weather(latlng: any) {
|
||||
this.action('weather', 'json', latlng);
|
||||
return this.action('weather', 'json', latlng);
|
||||
}
|
||||
|
||||
private launchAction(data) {
|
||||
this.action('launch', 'launch-action', data);
|
||||
return this.action('launch', 'launch-action', data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ export default class LinksApi extends BaseApi<StoreState> {
|
||||
getCommentsPage(path: Path, url: string, page: number) {
|
||||
const strictUrl = stringToTa(url);
|
||||
const endpoint = '/json/' + page + '/discussions/' + strictUrl + path;
|
||||
this.fetchLink(
|
||||
return this.fetchLink(
|
||||
endpoint,
|
||||
(res) => {
|
||||
if (res.data['link-update']['initial-discussions']) {
|
||||
@ -28,7 +28,7 @@ export default class LinksApi extends BaseApi<StoreState> {
|
||||
|
||||
getPage(path: Path, page: number) {
|
||||
const endpoint = '/json/' + page + '/submissions' + path;
|
||||
this.fetchLink(
|
||||
return this.fetchLink(
|
||||
endpoint,
|
||||
(dat) => {
|
||||
this.store.handleEvent(dat);
|
||||
@ -41,7 +41,7 @@ export default class LinksApi extends BaseApi<StoreState> {
|
||||
getSubmission(path: Path, url: string, callback) {
|
||||
const strictUrl = stringToTa(url);
|
||||
const endpoint = '/json/0/submission/' + strictUrl + path;
|
||||
this.fetchLink(
|
||||
return this.fetchLink(
|
||||
endpoint,
|
||||
(res) => {
|
||||
if (res.data?.['link-update']?.submission) {
|
||||
@ -118,7 +118,7 @@ export default class LinksApi extends BaseApi<StoreState> {
|
||||
}
|
||||
|
||||
private fetchLink(path: Path, result, fail, quit) {
|
||||
this.subscribe.bind(this)(
|
||||
return this.subscribe.bind(this)(
|
||||
path,
|
||||
'PUT',
|
||||
this.ship,
|
||||
|
@ -10,7 +10,7 @@ export default class PublishApi extends BaseApi {
|
||||
}
|
||||
|
||||
fetchNotebooks() {
|
||||
fetch('/publish-view/notebooks.json')
|
||||
return fetch('/publish-view/notebooks.json')
|
||||
.then(response => response.json())
|
||||
.then((json) => {
|
||||
this.handleEvent({
|
||||
@ -21,7 +21,7 @@ export default class PublishApi extends BaseApi {
|
||||
}
|
||||
|
||||
fetchNotebook(host: PatpNoSig, book: BookId) {
|
||||
fetch(`/publish-view/${host}/${book}.json`)
|
||||
return fetch(`/publish-view/${host}/${book}.json`)
|
||||
.then(response => response.json())
|
||||
.then((json) => {
|
||||
this.handleEvent({
|
||||
@ -34,7 +34,7 @@ export default class PublishApi extends BaseApi {
|
||||
}
|
||||
|
||||
fetchNote(host: PatpNoSig, book: BookId, note: NoteId) {
|
||||
fetch(`/publish-view/${host}/${book}/${note}.json`)
|
||||
return fetch(`/publish-view/${host}/${book}/${note}.json`)
|
||||
.then(response => response.json())
|
||||
.then((json) => {
|
||||
this.handleEvent({
|
||||
@ -48,7 +48,7 @@ export default class PublishApi extends BaseApi {
|
||||
}
|
||||
|
||||
fetchNotesPage(host: PatpNoSig, book: BookId, start: number, length: number) {
|
||||
fetch(`/publish-view/notes/${host}/${book}/${start}/${length}.json`)
|
||||
return fetch(`/publish-view/notes/${host}/${book}/${start}/${length}.json`)
|
||||
.then(response => response.json())
|
||||
.then((json) => {
|
||||
this.handleEvent({
|
||||
@ -63,7 +63,7 @@ export default class PublishApi extends BaseApi {
|
||||
}
|
||||
|
||||
fetchCommentsPage(host: PatpNoSig, book: BookId, note: NoteId, start: number, length: number) {
|
||||
fetch(`/publish-view/comments/${host}/${book}/${note}/${start}/${length}.json`)
|
||||
return fetch(`/publish-view/comments/${host}/${book}/${note}/${start}/${length}.json`)
|
||||
.then(response => response.json())
|
||||
.then((json) => {
|
||||
this.handleEvent({
|
||||
@ -78,6 +78,24 @@ export default class PublishApi extends BaseApi {
|
||||
});
|
||||
}
|
||||
|
||||
subscribeNotebook(who: PatpNoSig, book: BookId) {
|
||||
return this.publishAction({
|
||||
subscribe: {
|
||||
who,
|
||||
book
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
unsubscribeNotebook(who: PatpNoSig, book: BookId) {
|
||||
return this.publishAction({
|
||||
unsubscribe: {
|
||||
who,
|
||||
book
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
publishAction(act: any) {
|
||||
return this.action('publish', 'publish-action', act);
|
||||
}
|
||||
|
@ -6,31 +6,31 @@ import {S3Update} from '../../types/s3-update';
|
||||
export default class S3Api extends BaseApi<StoreState> {
|
||||
|
||||
setCurrentBucket(bucket: string) {
|
||||
this.s3Action({ 'set-current-bucket': bucket });
|
||||
return this.s3Action({ 'set-current-bucket': bucket });
|
||||
}
|
||||
|
||||
addBucket(bucket: string) {
|
||||
this.s3Action({ 'add-bucket': bucket });
|
||||
return this.s3Action({ 'add-bucket': bucket });
|
||||
}
|
||||
|
||||
removeBucket(bucket: string) {
|
||||
this.s3Action({ 'remove-bucket': bucket });
|
||||
return this.s3Action({ 'remove-bucket': bucket });
|
||||
}
|
||||
|
||||
setEndpoint(endpoint: string) {
|
||||
this.s3Action({ 'set-endpoint': endpoint });
|
||||
return this.s3Action({ 'set-endpoint': endpoint });
|
||||
}
|
||||
|
||||
setAccessKeyId(accessKeyId: string) {
|
||||
this.s3Action({ 'set-access-key-id': accessKeyId });
|
||||
return this.s3Action({ 'set-access-key-id': accessKeyId });
|
||||
}
|
||||
|
||||
setSecretAccessKey(secretAccessKey: string) {
|
||||
this.s3Action({ 'set-secret-access-key': secretAccessKey });
|
||||
return this.s3Action({ 'set-secret-access-key': secretAccessKey });
|
||||
}
|
||||
|
||||
private s3Action(data: any) {
|
||||
this.action('s3-store', 's3-action', data);
|
||||
return this.action('s3-store', 's3-action', data);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user