Skip to content

Commit

Permalink
Merge pull request #8 from DestinyItemManager/esm
Browse files Browse the repository at this point in the history
3.0: ES Modules, no more const enum
  • Loading branch information
bhollis authored Apr 19, 2020
2 parents 3aa46ec + 8dca992 commit 16e1082
Show file tree
Hide file tree
Showing 68 changed files with 17,333 additions and 14,575 deletions.
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"comments": false,
"presets": ["@babel/typescript"],
"plugins": [
[
"const-enum",
{
"transform": "constObject"
}
],
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This project implements TypeScript definitions and API helpers for the [Bungie.n

Feel free to fork this and use it to generate for your favorite language!

* [Dart](https://github.com/marquesinijatinha/bungie-api-dart/)
- [Dart](https://github.com/marquesinijatinha/bungie-api-dart/)

# Install

```
npm install bungie-api-ts
yarn add bungie-api-ts
```

# Interfaces and Enums
Expand Down Expand Up @@ -60,5 +60,5 @@ Destiny2.getProfile(...);
# Build

```
npm install && npm start
yarn && yarn start
```
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Prepare the generated source directory
rm -rf ./generated-src
mkdir -p generated-src
cp generator/http.d.ts generated-src
cp generator/http.ts generated-src

# Compile and run the generator
tsc -p tsconfig.json
Expand All @@ -17,8 +17,13 @@ touch ./docs/.nojekyll
rm -rf ./lib
mkdir -p lib
rsync -a --include '*/' --include '*.d.ts' --exclude '*' generated-src/ lib/

babel generated-src --out-dir lib --extensions ".ts"

tsc -p tsconfig-package.json

yarn prettier --write lib/**/*

# Copy package.json into lib - we'll publish lib as the package instead of the whole repo, so paths are nicer.
cp package.json lib/
cp README.md lib/
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions generator/generate-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export function indent(text: string, indentLevel: number) {
return lines.map((line) => ' '.repeat(indentLevel) + line).join('\n');
}

export function writeOutFile(filename: string, contents: string) {
mkdirp(path.dirname(filename), (err) => {
if (err) {
console.error(err);
} else {
fs.writeFile(filename, contents, null, (error) => {
console.log(error ? error : `Done with ${filename}!`);
});
}
});
export async function writeOutFile(filename: string, contents: string) {
try {
await mkdirp(path.dirname(filename));

fs.writeFile(filename, contents, null, (error) => {
console.log(error ? error : `Done with ${filename}!`);
});
} catch (e) {
console.error(e);
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion generator/type-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function addReachableComponentsFromComponent(
(component.allOf || []).forEach((schema: SchemaObject | ReferenceObject) => {
addDefinitions(allDefinitions, schema, doc);
});
if (component.additionalProperties) {
if (component.additionalProperties && typeof component.additionalProperties !== 'boolean') {
addDefinitions(allDefinitions, component.additionalProperties, doc);
}
}
Expand Down
8 changes: 6 additions & 2 deletions generator/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function typeMapping(schema: SchemaObject, doc: OpenAPIObject): string {
case 'object':
if (schema.allOf) {
return resolveSchemaType(schema.allOf[0], doc);
} else if (schema.additionalProperties && schema['x-dictionary-key']) {
} else if (
schema.additionalProperties &&
schema['x-dictionary-key'] &&
typeof schema.additionalProperties !== 'boolean'
) {
const keySchema: SchemaObject | ReferenceObject = schema['x-dictionary-key'];
const key = isReferenceObject(keySchema) ? 'number' : resolveSchemaType(keySchema, doc);
const val = resolveSchemaType(schema.additionalProperties, doc);
Expand All @@ -55,7 +59,7 @@ export function getReferencedTypes(schema: SchemaObject | ReferenceObject): stri
return getReferencedTypes(schema.items!);
} else if (schema.allOf) {
return getReferencedTypes(schema.allOf[0]);
} else if (schema.additionalProperties) {
} else if (schema.additionalProperties && typeof schema.additionalProperties !== 'boolean') {
return getReferencedTypes(schema.additionalProperties);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This project implements TypeScript definitions and API helpers for the [Bungie.n

Feel free to fork this and use it to generate for your favorite language!

* [Dart](https://github.com/marquesinijatinha/bungie-api-dart/)
- [Dart](https://github.com/marquesinijatinha/bungie-api-dart/)

# Install

```
npm install bungie-api-ts
yarn add bungie-api-ts
```

# Interfaces and Enums
Expand Down Expand Up @@ -60,5 +60,5 @@ Destiny2.getProfile(...);
# Build

```
npm install && npm start
yarn && yarn start
```
21 changes: 13 additions & 8 deletions lib/app/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ import { HttpClient } from '../http';
import { ApiUsage, Application } from './interfaces';
import { ServerResponse } from '../common';
export interface GetApplicationApiUsageParams {
/** ID of the application to get usage statistics. */
applicationId: number;
/** End time for query. Goes to now if not specified. */
end?: string;
/** Start time for query. Goes to 24 hours ago if not specified. */
start?: string;
/** ID of the application to get usage statistics. */
applicationId: number;
/** End time for query. Goes to now if not specified. */
end?: string;
/** Start time for query. Goes to 24 hours ago if not specified. */
start?: string;
}
/**
* Get API usage by application for time frame specified. You can go as far back as
* 30 days ago, and can ask for up to a 48 hour window of time in a single request.
* You must be authenticated with at least the ReadUserData permission to access
* this endpoint.
*/
export declare function getApplicationApiUsage(http: HttpClient, params: GetApplicationApiUsageParams): Promise<ServerResponse<ApiUsage>>;
export declare function getApplicationApiUsage(
http: HttpClient,
params: GetApplicationApiUsageParams
): Promise<ServerResponse<ApiUsage>>;
/** Get list of applications created by Bungie. */
export declare function getBungieApplications(http: HttpClient): Promise<ServerResponse<Application[]>>;
export declare function getBungieApplications(
http: HttpClient
): Promise<ServerResponse<Application[]>>;
50 changes: 14 additions & 36 deletions lib/app/api.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
"use strict";
/**
* Bungie.Net API
* These endpoints constitute the functionality exposed by Bungie.net, both for more traditional website functionality and for connectivity to Bungie video games and their related functionality.
*
* OpenAPI spec version: 2.8.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the bungie-api-ts code generator program.
* https://github.com/DestinyItemManager/bungie-api-ts
* Do not edit these files manually.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Get API usage by application for time frame specified. You can go as far back as
* 30 days ago, and can ask for up to a 48 hour window of time in a single request.
* You must be authenticated with at least the ReadUserData permission to access
* this endpoint.
*/
function getApplicationApiUsage(http, params) {
return http({
method: 'GET',
url: "https://www.bungie.net/Platform/App/ApiUsage/" + params.applicationId + "/",
params: {
end: params.end,
start: params.start
}
});
export function getApplicationApiUsage(http, params) {
return http({
method: 'GET',
url: `https://www.bungie.net/Platform/App/ApiUsage/${params.applicationId}/`,
params: {
end: params.end,
start: params.start,
},
});
}
exports.getApplicationApiUsage = getApplicationApiUsage;
/** Get list of applications created by Bungie. */
function getBungieApplications(http) {
return http({
method: 'GET',
url: 'https://www.bungie.net/Platform/App/FirstParty/'
});
export function getBungieApplications(http) {
return http({
method: 'GET',
url: 'https://www.bungie.net/Platform/App/FirstParty/',
});
}
exports.getBungieApplications = getBungieApplications;
25 changes: 5 additions & 20 deletions lib/app/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
"use strict";
/**
* Bungie.Net API
* These endpoints constitute the functionality exposed by Bungie.net, both for more traditional website functionality and for connectivity to Bungie video games and their related functionality.
*
* OpenAPI spec version: 2.8.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the bungie-api-ts code generator program.
* https://github.com/DestinyItemManager/bungie-api-ts
* Do not edit these files manually.
*/
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("../common"));
__export(require("../platform"));
__export(require("./api"));
__export(require("./interfaces"));
export * from '../common';
export * from '../platform';
export * from '../http';
export * from './api';
export * from './interfaces';
Loading

0 comments on commit 16e1082

Please sign in to comment.