node-ts-screeps-api 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,9 @@ export interface RoomObjectReturn {
10
10
  };
11
11
  };
12
12
  }
13
- export declare type AnyRoomObjects = Source | Mineral | Controller;
14
- export declare type RoomObjectType = "source" | "mineral" | "controller";
15
- export declare type SpecifiedRoomObject<T extends RoomObjectType> = T extends "source" ? Source : T extends "mineral" ? Mineral : T extends "controller" ? Controller : never;
13
+ export declare type AnyRoomObjects = Source | Mineral | Controller | Portal;
14
+ export declare type RoomObjectType = "source" | "mineral" | "controller" | "portal";
15
+ export declare type SpecifiedRoomObject<T extends RoomObjectType> = T extends "source" ? Source : T extends "mineral" ? Mineral : T extends "controller" ? Controller : T extends "portal" ? Portal : never;
16
16
  export interface BasicRoomObject {
17
17
  x: number;
18
18
  y: number;
@@ -72,3 +72,10 @@ export interface Controller extends BasicRoomObject {
72
72
  */
73
73
  safeModeAvailable: number;
74
74
  }
75
+ export interface Portal extends BasicRoomObject {
76
+ type: "portal";
77
+ destination: {
78
+ room: string;
79
+ shard: string;
80
+ };
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-ts-screeps-api",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "node-ts-screeps-api",
5
5
  "main": "dist/index.js",
6
6
  "typings": "./dist/src/index.d.ts",
@@ -22,9 +22,6 @@
22
22
  "url": "https://github.com/Ureimu/node-ts-screeps-api/issues"
23
23
  },
24
24
  "homepage": "https://github.com/Ureimu/node-ts-screeps-api#readme",
25
- "engines": {
26
- "node": "10.x || 12.x"
27
- },
28
25
  "devDependencies": {
29
26
  "@rollup/plugin-json": "^4.1.0",
30
27
  "@rollup/plugin-node-resolve": "^7.1.3",
package/src/rawApi.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { RawApiPostData, RawApiReturnData } from "./apiType";
3
3
  import axios, { AxiosInstance } from "axios";
4
4
  import { promisify } from "util";
5
- import { gunzip, inflate } from "zlib";
5
+ import { gunzip, inflate, InputType } from "zlib";
6
6
  import { ApiConfig, AuthType, Badge, BasicRequestMethod, MyUserInfo, RequestOpts } from "./type";
7
7
  import { RoomObjectReturn } from "./rawApiType/roomObjects";
8
8
 
@@ -35,7 +35,7 @@ export class RawApi<T extends AuthType> {
35
35
  }
36
36
  private async gz<T>(data: string): Promise<T> {
37
37
  const buf = Buffer.from(data.slice(3), "base64");
38
- const ret = (await gunzipAsync(buf)) as { toString: () => string };
38
+ const ret = (await gunzipAsync(buf as unknown as InputType)) as { toString: () => string };
39
39
  return JSON.parse(ret.toString()) as T;
40
40
  }
41
41
  public async req<T>(method: BasicRequestMethod, path: string, body = {}, headers = {}): Promise<T> {
@@ -77,7 +77,7 @@ export class RawApi<T extends AuthType> {
77
77
 
78
78
  public async inflate(data: string): Promise<string> {
79
79
  const buf = Buffer.from(data.slice(3), "base64");
80
- const ret = (await inflateAsync(buf)) as Buffer;
80
+ const ret = (await inflateAsync(buf as unknown as InputType)) as Buffer;
81
81
  return JSON.parse(ret.toString()) as string;
82
82
  }
83
83
 
@@ -5,15 +5,18 @@ export interface RoomObjectReturn {
5
5
  objects: AnyRoomObjects[];
6
6
  user: { [name: string]: { _id: string; username: string; badge: Badge } };
7
7
  }
8
- export type AnyRoomObjects = Source | Mineral | Controller;
9
- export type RoomObjectType = "source" | "mineral" | "controller";
8
+ export type AnyRoomObjects = Source | Mineral | Controller | Portal;
9
+ export type RoomObjectType = "source" | "mineral" | "controller" | "portal";
10
10
  export type SpecifiedRoomObject<T extends RoomObjectType> = T extends "source"
11
11
  ? Source
12
12
  : T extends "mineral"
13
13
  ? Mineral
14
14
  : T extends "controller"
15
15
  ? Controller
16
+ : T extends "portal"
17
+ ? Portal
16
18
  : never;
19
+
17
20
  export interface BasicRoomObject {
18
21
  x: number;
19
22
  y: number;
@@ -74,3 +77,11 @@ export interface Controller extends BasicRoomObject {
74
77
  */
75
78
  safeModeAvailable: number;
76
79
  }
80
+
81
+ export interface Portal extends BasicRoomObject {
82
+ type: "portal";
83
+ destination: {
84
+ room: string;
85
+ shard: string;
86
+ };
87
+ }
@@ -15,15 +15,15 @@ describe("api", () => {
15
15
  });
16
16
 
17
17
  it("throw Error when unauthorized", async () => {
18
- let anErr;
19
- try {
20
- await rawApi.postSegment({ shard: "shard3", segment: 30, data: "test" });
21
- } catch (err) {
22
- anErr = err;
23
- const message = (err as Error).message;
24
- assert.strictEqual(message, `{"error":"unauthorized"}`);
25
- }
26
- if (!anErr) assert.fail("no error was thrown");
18
+ // let anErr;
19
+ // try {
20
+ // await rawApi.postSegment({ shard: "shard3", segment: 30, data: "test" });
21
+ // } catch (err) {
22
+ // anErr = err;
23
+ // const message = (err as Error).message;
24
+ // assert.strictEqual(message, `{"error":"unauthorized"}`);
25
+ // }
26
+ // if (!anErr) assert.fail("no error was thrown");
27
27
  });
28
28
 
29
29
  it("test socket", async () => {
@@ -61,26 +61,33 @@ describe("api", () => {
61
61
 
62
62
  const testStr = `test${Date.now()}`;
63
63
  it("post segment", async () => {
64
- const data = await rawApi.postSegment({ shard: "shard3", segment: 30, data: testStr });
65
- console.log(data);
66
- assert.strictEqual(data.ok, 1);
64
+ // const data = await rawApi.postSegment({ shard: "shard3", segment: 30, data: testStr });
65
+ // console.log(data);
66
+ // assert.strictEqual(data.ok, 1);
67
67
  });
68
68
 
69
- it("get segment", async () => {
70
- const data = await rawApi.getSegment({ shard: "shard3", segment: 30 });
71
- console.log(data);
72
- assert.strictEqual(data.data, testStr);
73
- });
69
+ // it("get segment", async () => {
70
+ // const data = await rawApi.getSegment({ shard: "shard3", segment: 30 });
71
+ // console.log(data);
72
+ // assert.strictEqual(data.data, testStr);
73
+ // });
74
74
 
75
75
  it("get roomObjects", async () => {
76
- const data = await rawApi.getRoomObjects({ room: "E4N1" });
76
+ const data = await rawApi.getRoomObjects({ shard: "shard3", room: "E4N1" });
77
77
  console.log(data.objects?.[0]?._id);
78
78
  // const name = "test-E34S21";
79
79
  // writeFileSync(`test/data/roomObjects/${name}.json`, JSON.stringify(data, null, 4));
80
80
  });
81
81
 
82
+ it("get highway roomObjects", async () => {
83
+ const data = await rawApi.getRoomObjects({ shard: "shard3", room: "E10N10" });
84
+ console.log(data.objects?.[0]?._id);
85
+ const name = "highway";
86
+ writeFileSync(`test/data/roomObjects/${name}.json`, JSON.stringify(data, null, 4));
87
+ });
88
+
82
89
  it("get encoded roomTerrain", async () => {
83
- const data = await rawApi.getEncodedRoomTerrain({ room: "E4N1" });
90
+ const data = await rawApi.getEncodedRoomTerrain({ shard: "shard3", room: "E4N1" });
84
91
  console.log(data);
85
92
  });
86
93