Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Convert codebase to TypeScript. #92

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime"]
"plugins": ["@babel/plugin-transform-runtime", "add-module-exports"]
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@babel/core": "^7.12.10",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.10",
"babel-plugin-add-module-exports": "^1.0.4",
"chai": "^4.2.0",
"eslint": "^7.15.0",
"eslint-config-airbnb": "^18.2.1",
Expand Down
4 changes: 2 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const helper = require('./helper');
import helper from './helper';

async function api(baseUrl, config, method, params) {
const url = new URL(baseUrl);
Expand Down Expand Up @@ -45,4 +45,4 @@ async function api(baseUrl, config, method, params) {
}
}

module.exports = api;
export default api;
6 changes: 3 additions & 3 deletions src/events_wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const queues = require('./resources/queues');
const events = require('./resources/events');
import queues from './resources/queues';
import events from './resources/events';

function sleep(ms) {
// TODO add jitter.
Expand Down Expand Up @@ -72,4 +72,4 @@ function eventsWrapper(config) {
return callOnEachEvent;
}

module.exports = eventsWrapper;
export default eventsWrapper;
6 changes: 3 additions & 3 deletions src/helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fetch = require('isomorphic-fetch');
const FormData = require('isomorphic-form-data');
import fetch from 'isomorphic-fetch';
import FormData from 'isomorphic-form-data';

module.exports = {
export default {
fetch,
FormData,
};
29 changes: 14 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import parseConfigFile from './zuliprc';

const api = require('./api');

const accounts = require('./resources/accounts');
const streams = require('./resources/streams');
const messages = require('./resources/messages');
const queues = require('./resources/queues');
const events = require('./resources/events');
const users = require('./resources/users');
const emojis = require('./resources/emojis');
const typing = require('./resources/typing');
const reactions = require('./resources/reactions');
const server = require('./resources/server');
const filters = require('./resources/filters');
const eventsWapper = require('./events_wrapper');
import api from './api';
import accounts from './resources/accounts';
import streams from './resources/streams';
import messages from './resources/messages';
import queues from './resources/queues';
import events from './resources/events';
import users from './resources/users';
import emojis from './resources/emojis';
import typing from './resources/typing';
import reactions from './resources/reactions';
import server from './resources/server';
import filters from './resources/filters';
import eventsWapper from './events_wrapper';

function getCallEndpoint(config) {
return function callEndpoint(endpoint, method = 'GET', params) {
Expand Down Expand Up @@ -64,4 +63,4 @@ async function zulip(initialConfig) {
return resources(config);
}

module.exports = zulip;
export default zulip;
4 changes: 2 additions & 2 deletions src/resources/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const helper = require('../helper');
import helper from '../helper';

function accounts(config) {
return {
Expand All @@ -16,4 +16,4 @@ function accounts(config) {
};
}

module.exports = accounts;
export default accounts;
4 changes: 2 additions & 2 deletions src/resources/emojis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function emojis(config) {
return {
Expand All @@ -9,4 +9,4 @@ function emojis(config) {
};
}

module.exports = emojis;
export default emojis;
4 changes: 2 additions & 2 deletions src/resources/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function events(config) {
return {
Expand All @@ -9,4 +9,4 @@ function events(config) {
};
}

module.exports = events;
export default events;
4 changes: 2 additions & 2 deletions src/resources/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function filters(config) {
return {
Expand All @@ -9,4 +9,4 @@ function filters(config) {
};
}

module.exports = filters;
export default filters;
4 changes: 2 additions & 2 deletions src/resources/messages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function messages(config) {
const baseURL = `${config.apiURL}/messages`;
Expand Down Expand Up @@ -71,4 +71,4 @@ function messages(config) {
};
}

module.exports = messages;
export default messages;
4 changes: 2 additions & 2 deletions src/resources/queues.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function queues(config) {
return {
Expand All @@ -17,4 +17,4 @@ function queues(config) {
};
}

module.exports = queues;
export default queues;
4 changes: 2 additions & 2 deletions src/resources/reactions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function reactions(config) {
const url = (messageID) => `${config.apiURL}/messages/${messageID}/reactions`;
Expand All @@ -13,4 +13,4 @@ function reactions(config) {
};
}

module.exports = reactions;
export default reactions;
4 changes: 2 additions & 2 deletions src/resources/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function server(config) {
return {
Expand All @@ -9,4 +9,4 @@ function server(config) {
};
}

module.exports = server;
export default server;
4 changes: 2 additions & 2 deletions src/resources/streams.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function streams(config) {
return {
Expand Down Expand Up @@ -35,4 +35,4 @@ function streams(config) {
};
}

module.exports = streams;
export default streams;
4 changes: 2 additions & 2 deletions src/resources/typing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function typing(config) {
return {
Expand All @@ -13,4 +13,4 @@ function typing(config) {
};
}

module.exports = typing;
export default typing;
4 changes: 2 additions & 2 deletions src/resources/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const api = require('../api');
import api from '../api';

function users(config) {
return {
Expand Down Expand Up @@ -45,4 +45,4 @@ function users(config) {
};
}

module.exports = users;
export default users;