startgg-helper-node 2.1.0 → 2.2.2

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.
package/jsUtil.js ADDED
@@ -0,0 +1 @@
1
+ export * from "startgg-helper/util"
package/package.json CHANGED
@@ -1,8 +1,22 @@
1
1
  {
2
2
  "name": "startgg-helper-node",
3
- "version": "2.1.0",
3
+ "version": "2.2.2",
4
4
  "description": "A set of functions and classes useful to communicate with the start.gg API.",
5
5
  "main": "main.js",
6
+ "module": "main.js",
7
+ "exports": {
8
+ ".": {
9
+ "default": "./main.js"
10
+ },
11
+ "./util": {
12
+ "default": "./jsUtil.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "main.js",
17
+ "client.js",
18
+ "jsUtil.js"
19
+ ],
6
20
  "scripts": {
7
21
  "test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js --silent"
8
22
  },
@@ -23,7 +37,7 @@
23
37
  "homepage": "https://gitlab.com/TwilCynder/startgg-helper#readme",
24
38
  "dependencies": {
25
39
  "graphql-request": "^7.1.2",
26
- "startgg-helper": "^2.1.0"
40
+ "startgg-helper": "^2.2.1"
27
41
  },
28
42
  "type": "module",
29
43
  "devDependencies": {
package/test/common.js DELETED
@@ -1,11 +0,0 @@
1
- import { GraphQLClient } from "graphql-request"
2
-
3
- const endpoint = "https://www.start.gg/api/-/gql"
4
- const headers = {
5
- "client-version": "21",
6
- 'Content-Type': 'application/json'
7
- }
8
-
9
- export function makeClient(){
10
- return new GraphQLClient(endpoint, {headers: headers});
11
- }
@@ -1,7 +0,0 @@
1
- {
2
- "typeAcquisition": {
3
- "include": [
4
- "jest"
5
- ]
6
- }
7
- }
package/test/long.js DELETED
@@ -1,39 +0,0 @@
1
- import { Query } from "startgg-helper";
2
- import { StartGGDelayQueryLimiter } from "startgg-helper";
3
-
4
- const schema = `
5
- query Sets($slug: String, $page: Int, $perPage: Int) {
6
- event(slug: $slug){
7
- sets(page: $page, perPage: $perPage){
8
- nodes {
9
- id
10
- }
11
- }
12
- }
13
- }
14
- `
15
-
16
- let query = new Query(schema, 3);
17
- export async function testLong(client){
18
- try {
19
- let limiter = new StartGGDelayQueryLimiter();
20
-
21
- let promises = [];
22
- for (let i = 0; i < 50; i++){
23
- for (let j = 0; j < 2; j++){
24
- promises.push(query.execute(client, {
25
- slug: `tournament/stock-o-clock-${i}/event/1v1-ultimate`,
26
- page: j,
27
- perPage: 10
28
- }, limiter));
29
- }
30
- }
31
- let result = await Promise.all(promises);
32
- limiter.stop();
33
- return result;
34
- } catch (err){
35
- console.error(err);
36
- return null;
37
- }
38
-
39
- }
package/test/main.js DELETED
@@ -1,48 +0,0 @@
1
- import { deep_get } from "startgg-helper";
2
- import { makeClient } from "./common.js";
3
- import { testLong } from "./long.js";
4
- import { testPaginated } from "./paginated.js";
5
- import { testPaginatedComplex } from "./paginatedComplex.js";
6
- import { testShort } from "./short.js";
7
- import { ArgumentsManager } from "@twilcynder/arguments-parser"
8
- import { testUpsets } from "./upsets.js";
9
-
10
- let {short, long, paginated, paginatedComplex, upsets} = new ArgumentsManager()
11
- .addSwitch(["-s", "--short"], {})
12
- .addSwitch(["-l", "--long"], {})
13
- .addSwitch(["-p", "--paginated"], {})
14
- .addSwitch(["-P", "--paginatedComplex"], {})
15
- .addSwitch(["-u", "--upsets"], {})
16
- .enableHelpParameter()
17
- .parseProcessArguments()
18
-
19
- let client = makeClient();
20
-
21
- if (short){
22
- console.log("Testing : single query");
23
- console.log(await testShort(client));
24
- }
25
-
26
- if (long){
27
- console.log("Testing : 100ish queries, with delay-based limiter");
28
- console.log(await testLong(client));
29
- }
30
-
31
- if (paginated){
32
- console.log("Testing : paginated query");
33
- console.log(await testPaginated(client));
34
- }
35
-
36
- if (paginatedComplex){
37
- console.log("Testing : paginated query");
38
- let res = await testPaginatedComplex(client);
39
- console.log(res, deep_get(res, "event.sets.nodes.length"));
40
- }
41
-
42
- if (upsets){
43
- console.log("Testing : upsets calculation");
44
- let res = await testUpsets(client);
45
- for (let upset of res){
46
- console.log(upset);
47
- }
48
- }
package/test/main.test.js DELETED
@@ -1,42 +0,0 @@
1
- import { makeClient } from "./common.js";
2
- import { testLong } from "./long.js";
3
- import { testPaginated } from "./paginated.js";
4
- import { testPaginatedComplex } from "./paginatedComplex.js";
5
- import { testShort } from "./short";
6
- import { testUpsets } from "./upsets.js";
7
-
8
- test("Single query (event results)", async () => {
9
- expect(await testShort(makeClient())).toBeTruthy();
10
- });
11
-
12
- test("100ish queries with delay-based limiter (sets)", async () => {
13
- expect(await testLong(makeClient())).toBeTruthy();
14
- }, 120000);
15
-
16
- test("Paginated query (sets)", async () => {
17
- expect(await testPaginated(makeClient())).toBeTruthy();
18
- }, 60000);
19
-
20
- test("Paginated query (sets) with advanced options", async () => {
21
- let res = await testPaginatedComplex(makeClient());
22
- expect(res).toBeTruthy();
23
- expect(res.event.tournament).toBeTruthy();
24
- expect(res.event.sets.nodes.length).toBe(100);
25
- }, 60000);
26
-
27
-
28
- let upsets = [
29
- [1,1],
30
- [1,0],
31
- [1,1],
32
- [1,0],
33
- [0,1],
34
- [0,0],
35
- [0,1],
36
- [0,0],
37
- ]
38
- test("Calculate upset factor on 8 sets across 2 events", async () => {
39
- let res = await testUpsets(makeClient());
40
- expect(res).toBeTruthy();
41
- expect(res).toStrictEqual(upsets);
42
- }, 60000)
package/test/paginated.js DELETED
@@ -1,9 +0,0 @@
1
- import { Query } from "startgg-helper";
2
-
3
- import { schema } from "./paginatedCommon.js";
4
-
5
- let query = new Query(schema, 3);
6
- export async function testPaginated(client){
7
- let result = await query.executePaginated(client, {slug: "tournament/tls-mad-ness-25/event/1v1-ultimate"}, "event.sets");
8
- return result;
9
- }
@@ -1,19 +0,0 @@
1
- export const schema = `
2
- query Sets($slug: String, $page: Int, $perPage: Int) {
3
- event(slug: $slug){
4
- slug
5
- tournament {
6
- name
7
- numAttendees
8
- }
9
- sets(page: $page, perPage: $perPage){
10
- pageInfo {
11
- totalPages
12
- }
13
- nodes {
14
- id
15
- }
16
- }
17
- }
18
- }
19
- `
@@ -1,13 +0,0 @@
1
- import { Query } from "startgg-helper";
2
-
3
- import { schema } from "./paginatedCommon.js";
4
-
5
- let query = new Query(schema, 3);
6
- export async function testPaginatedComplex(client){
7
- let result = await query.executePaginated(client, {slug: "tournament/tls-mad-ness-25/event/1v1-ultimate"}, "event.sets", null, {
8
- perPage: 10,
9
- includeWholeQuery: Query.IWQModes.INLINE,
10
- maxElements: 100
11
- });
12
- return result;
13
- }
package/test/short.js DELETED
@@ -1,32 +0,0 @@
1
- import { Query } from "startgg-helper";
2
- import { processData } from "./testUtil.js";
3
-
4
- const schema = `
5
- query EventStandingsQuery($slug: String!) {
6
- event(slug: $slug) {
7
- id
8
- entrants (query: {perPage: 500}){
9
- nodes {
10
- id
11
- name
12
- participants {
13
- player {
14
- id
15
- gamerTag
16
- }
17
- user {
18
- id
19
- slug
20
- }
21
- }
22
- }
23
- }
24
- }
25
- }
26
- `
27
-
28
- let query = new Query(schema, 3);
29
- export async function testShort(client){
30
- let result = await query.execute(client, {slug: "tournament/tls-mad-ness-25/event/1v1-ultimate"});
31
- return processData(result, "event");
32
- }
package/test/testUtil.js DELETED
@@ -1,3 +0,0 @@
1
- export function processData(result, key){
2
- return (result && result[key]) ? result[key] : null;
3
- }
package/test/upsets.js DELETED
@@ -1,76 +0,0 @@
1
- import { Query } from "startgg-helper";
2
- import { StartGGDelayQueryLimiter } from "startgg-helper";
3
- import { getDoubleEliminationUpsetFactorFromSet } from "startgg-helper";
4
-
5
- const schema = `
6
- query Sets($slug: String, $page: Int, $perPage: Int) {
7
- event(slug: $slug){
8
- sets(page: $page, perPage: $perPage){
9
- nodes {
10
- round
11
- fullRoundText
12
- slots{
13
- entrant {
14
- name
15
- participants {
16
- player {
17
- id
18
- gamerTag
19
- }
20
- user {
21
- id
22
- slug
23
- }
24
- }
25
- initialSeedNum
26
- }
27
- standing {
28
- placement
29
- stats {
30
- score {
31
- value
32
- }
33
- }
34
- }
35
- }
36
- }
37
- }
38
- }
39
- }
40
- `
41
-
42
- let query = new Query(schema, 3);
43
- export async function testUpsets(client){
44
- let limiter = new StartGGDelayQueryLimiter();
45
-
46
- try {
47
-
48
- let promises = [];
49
- for (let i = 1; i < 3; i++){
50
- for (let j = 0; j < 2; j++){
51
- promises.push(query.execute(client, {
52
- slug: `tournament/stock-o-clock-${i}/event/1v1-ultimate`,
53
- page: j,
54
- perPage: 2
55
- }, limiter));
56
- }
57
- }
58
- let result = await Promise.all(promises);
59
-
60
- let upsets = []
61
-
62
- for (let event of result){
63
- if (!event || !event.event) continue;
64
- for (let set of event.event.sets.nodes){
65
- upsets.push(getDoubleEliminationUpsetFactorFromSet(set));
66
- }
67
- }
68
-
69
- return upsets;
70
- } catch (err){
71
- console.error(err);
72
- return null;
73
- } finally {
74
- limiter.stop();
75
- }
76
- }