Skip to content

Commit

Permalink
Fix JSDocs, for real this time
Browse files Browse the repository at this point in the history
Turns out that correlation does, in fact, not equal causation, and my previous theory was false. Instead it has... something...? to do with when/where the modules are require()'d? I have literally no idea why, but when copying all the request type require()s into the index file as well, they seem to be loaded fine.

Might also just be a VS Code thing, since I'm pretty sure that in the original version 1.0.0, the typings worked when I tested it. ¯\_(ツ)_/¯
  • Loading branch information
anjo0803 committed Jul 29, 2023
1 parent 02b6a93 commit ae6e4e2
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 24 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ providing a variety of enums for easy requests-building and understanding of res
offering additional methods and customisation for API interactions to support more advanced and/or
niche use cases.

The current NationScript version (1.0.5) is tailored to version `12` of the NS API and supports all
endpoints it offers.
NationScript is tailored to version `12` of the NS API and supports all endpoints it offers.

## Installation
NationScript is available via npm:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nationscript",
"version": "1.0.5",
"version": "1.0.6",
"description": "Library for interacting with the NationStates API",
"author": "anjo/Tepertopia (https://www.nationstates.net/tepertopia)",
"license": "MPL-2.0",
Expand Down
28 changes: 28 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,31 @@ exports.NationPrivateShard = SHARDS.NationPrivateShard;
exports.RegionShard = SHARDS.RegionShard;
exports.WorldShard = SHARDS.WorldShard;
exports.WAShard = SHARDS.WAShard;


/*
* For some reason, VS Code does not properly load these when require()'d in the API module, and
* including them here seems to fix it...?
* IDK why that happens, but until I figure out a proper solution, this should probably stay here.
*/
const {
CardIndividualRequest,
CardWorldRequest
} = require('./requests/card');
const { NationRequest } = require('./requests/nation');
const { RegionRequest } = require('./requests/region');
const { WorldRequest } = require('./requests/world');
const { WARequest } = require('./requests/wa');
const {
IssueCommand,
RMBPostCommand,
DispatchAddCommand,
DispatchDeleteCommand,
DispatchEditCommand,
GiftCardCommand
} = require('./requests/command');
const {
TGRequest,
UserAgentRequest,
VersionRequest
} = require('./requests/misc');
4 changes: 2 additions & 2 deletions src/requests/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CardIndividualRequest extends ShardableRequest {
* @returns {Promise<Card>} A card object holding all data returned.
*/
async send() {
return new exports.Card(await super.send('CARD'));
return new Card(await super.send('CARD'));
}

/*
Expand Down Expand Up @@ -153,7 +153,7 @@ class CardWorldRequest extends ShardableRequest {
* @returns {Promise<Card[]>} An list of card objects representing those in the nation's deck.
*/
async send() {
return new exports.CardWorld(await super.send('CARDS'));
return new CardWorld(await super.send('CARDS'));
}


Expand Down
16 changes: 8 additions & 8 deletions src/requests/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @returns {string} The string value of the named attribute, or `undefined` if not found.
* @ignore
*/
exports.attr = function(obj, name) {
exports.attr = (obj, name) => {
return obj?.['$attrs']?.[name];
}

Expand All @@ -23,7 +23,7 @@ exports.attr = function(obj, name) {
* @returns {string} The string value at the given position, or `null` if not found.
* @ignore
*/
exports.txt = function(obj, property, index = 0) {
exports.txt = (obj, property, index = 0) => {
let x = obj?.[property];
if(Array.isArray(x)) return x[index]?.toString().trim();
else if(x) return x.toString().trim();
Expand All @@ -38,7 +38,7 @@ exports.txt = function(obj, property, index = 0) {
* @returns {number} The numerical value at the given position, or `NaN` if not found.
* @ignore
*/
exports.num = function(obj, property, index = 0) {
exports.num = (obj, property, index = 0) => {
let val = exports.txt(obj, property, index);
if(/^\d+\.\d+$/.test(val)) return parseFloat(val);
else if(/^\d+$/.test(val)) return parseInt(val);
Expand All @@ -53,7 +53,7 @@ exports.num = function(obj, property, index = 0) {
* @returns {any[]} The array of values at the given position, or `null` if not found.
* @ignore
*/
exports.arr = function(obj, property, index = 0) {
exports.arr = (obj, property, index = 0) => {
let ret = obj?.[property];
if(ret === undefined) return null;

Expand All @@ -69,7 +69,7 @@ exports.arr = function(obj, property, index = 0) {
* @returns {boolean} `true` if iterable, `false` if not.
* @ignore
*/
exports.iterable = function(obj) {
exports.iterable = (obj) => {
if(obj == null) return false;
return typeof obj[Symbol.iterator] === 'function';
}
Expand All @@ -81,7 +81,7 @@ exports.iterable = function(obj) {
* @returns The return value of the handler function.
* @ignore
*/
exports.handle = function(root, handler) {
exports.handle = (root, handler) => {
if(root === undefined || typeof handler !== 'function') return undefined;
else return handler(root);
}
Expand All @@ -93,7 +93,7 @@ exports.handle = function(root, handler) {
* @returns A list with the results from the handler function for each element of the root.
* @ignore
*/
exports.handleList = function(root, handler) {
exports.handleList = (root, handler) => {
if(root === undefined || typeof handler !== 'function') return [];
let ret = [];
let iterate = exports.secureArray(root);
Expand All @@ -107,7 +107,7 @@ exports.handleList = function(root, handler) {
* @returns {any[]} The value, if it's an array, otherwise a single-element array with the value.
* @ignore
*/
exports.secureArray = function(arr) {
exports.secureArray = (arr) => {
if(!Array.isArray(arr)) arr = [arr];
return arr;
}
12 changes: 6 additions & 6 deletions src/requests/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ function same(date1, date2) {

/* === Exports === */

exports.DumpRequest = DumpRequest;
exports.CardDumpRequest = CardDumpRequest;
exports.NationDumpRequest = NationDumpRequest;
exports.RegionDumpRequest = RegionDumpRequest;

/**
* Supported ways of getting Daily Data Dump contents.
* @enum number
*/
exports.DumpMode = {
exports.DumpMode = {
/**
* Download the Dump, then read the local copy. Makes one API request.
*/
Expand All @@ -386,8 +391,3 @@ exports.DumpMode = {
*/
READ_REMOTE: 4
};

exports.DumpRequest = DumpRequest;
exports.CardDumpRequest = CardDumpRequest;
exports.NationDumpRequest = NationDumpRequest;
exports.RegionDumpRequest = RegionDumpRequest;
4 changes: 2 additions & 2 deletions src/requests/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('./base');

/**
* @summary Request subclass for building requests to the telegrams API.
* Request subclass for building requests to the telegrams API.
*/
class TGRequest extends ParameterRequest {

Expand Down Expand Up @@ -141,5 +141,5 @@ function streamToString(stream) {
}

exports.TGRequest = TGRequest;
exports.UserAgentRequest = UserAgentRequest;
exports.VersionRequest = VersionRequest;
exports.UserAgentRequest = UserAgentRequest;
2 changes: 1 addition & 1 deletion src/requests/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const { VoteTally, parseVoteTally } = require('../typedefs/vote-tally');
const { ZombieDataRegion, parseZombieRegion } = require('../typedefs/zombie-data-region');

/**
* @summary Request subclass for building requests to the regions endpoint of the API.
* Request subclass for building requests to the regions endpoint of the API.
*/
class RegionRequest extends ShardableRequest {
constructor(region) {
Expand Down
2 changes: 1 addition & 1 deletion src/requests/wa.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { Proposal, parseProposal } = require('../typedefs/proposal');
const { Resolution, parseResolution } = require('../typedefs/resolution');

/**
* @summary Request subclass for building and customising requests to the WA endpoint of the API.
* Request subclass for building and customising requests to the WA endpoint of the API.
*/
class WARequest extends ShardableRequest {
constructor(council) {
Expand Down
2 changes: 1 addition & 1 deletion src/requests/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const { Poll, parsePoll } = require('../typedefs/poll');
const { TGQueue, parseTGQueue } = require('../typedefs/tg-queue');

/**
* @summary Request subclass for building requests to the world endpoint of the API.
* Request subclass for building requests to the world endpoint of the API.
*/
class WorldRequest extends ShardableRequest {

Expand Down

0 comments on commit ae6e4e2

Please sign in to comment.