This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mods): add incursion t3 chest mods
- Loading branch information
Showing
11 changed files
with
2,747 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const ts = require('typescript'); | ||
|
||
const { apiEndpoint } = require('./util'); | ||
|
||
// creates a union type for all possible string values of `item_class` | ||
|
||
itemClasses().then(item_classes => { | ||
const ids = item_classes.map(({ id }) => id); | ||
const type = ts.createTypeAliasDeclaration( | ||
[], | ||
[], | ||
'ItemClassId', | ||
[], | ||
ts.createUnionTypeNode(ids.map(id => ts.createLiteral(id))), | ||
); | ||
|
||
// print ts source | ||
const source_file = ts.createSourceFile( | ||
'schema.ts', | ||
'', | ||
ts.ScriptTarget.Latest, | ||
false, | ||
ts.ScriptKind.TS, | ||
); | ||
const printer = ts.createPrinter(); | ||
const source = printer.printNode(ts.EmitHint.Unspecified, type, source_file); | ||
|
||
console.log(source); | ||
}); | ||
|
||
async function itemClasses(options = {}) { | ||
const { | ||
api_root = 'http://localhost:3000/', | ||
auth_token = 'allowme', | ||
} = options; | ||
|
||
const endpoint = '/find/ItemClasses/'; | ||
const params = { page_size: Number.MAX_SAFE_INTEGER }; | ||
|
||
const body = await apiEndpoint(endpoint, { api_root, auth_token, params }); | ||
return body.result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const fs = require('fs'); | ||
const http = require('http'); | ||
const { URL } = require('url'); | ||
const { promisify } = require('util'); | ||
|
||
const writeFile = promisify(fs.writeFile); | ||
|
||
module.exports = async function apiEndpoint(endpoint, options = {}) { | ||
const { | ||
api_root = 'http://localhost:3000/', | ||
auth_token = 'allowme', | ||
params = {}, | ||
} = options; | ||
|
||
const api_url = new URL(endpoint, api_root); | ||
setParams(api_url, params); | ||
|
||
const body = await httpGet(api_url, { | ||
headers: { Authorization: auth_token }, | ||
}); | ||
|
||
const json = JSON.parse(body); | ||
return json; | ||
}; | ||
|
||
function identity(arg) { | ||
return arg; | ||
} | ||
|
||
function setParams(url, params) { | ||
if (params === null || typeof params !== 'object') { | ||
throw new Error('no object given'); | ||
} | ||
|
||
for (const key of Object.keys(params)) { | ||
url.searchParams.set(key, params[key]); | ||
} | ||
|
||
return url; | ||
} | ||
|
||
/** | ||
* | ||
* @param {URL} url | ||
* @param {*} options | ||
*/ | ||
function httpGet(url, options = {}) { | ||
return new Promise((resolve, reject) => { | ||
let data = ''; | ||
|
||
http | ||
.get( | ||
{ | ||
host: url.hostname, | ||
port: url.port, | ||
path: `${url.pathname}${url.search}`, | ||
headers: { | ||
Authorization: 'allowme', | ||
}, | ||
}, | ||
res => { | ||
res.on('data', chunk => (data += chunk)); | ||
res.on('end', () => { | ||
if (res.statusCode === 200) { | ||
resolve(data); | ||
} else { | ||
reject(data); | ||
} | ||
}); | ||
}, | ||
) | ||
.on('error', e => reject(e)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const apiEndpoint = require('./apiEndpoint'); | ||
|
||
module.exports = { apiEndpoint }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.