Skip to content

Commit

Permalink
chore(core,docs,logstf): document all of logstf and add tests with ci (
Browse files Browse the repository at this point in the history
  • Loading branch information
c43721 authored Nov 8, 2024
2 parents a6f601d + 85ac123 commit 99e7b42
Show file tree
Hide file tree
Showing 22 changed files with 716 additions and 22 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/javascript-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: ci
on:
push:
branches: [main]
paths:
- "javascript-sdk/**"
pull_request:
branches: [main]
paths:
- "javascript-sdk/**"

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Set up Deno
uses: denoland/setup-deno@v2

- name: Test
working-directory: ./javascript-sdk
run: deno task test

publish-dry-run:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Set up Deno
uses: denoland/setup-deno@v2

- name: Dry Publish
run: deno publish --dry-run --config javascript-sdk/deno.json
3 changes: 3 additions & 0 deletions .github/workflows/publish-javscript-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ jobs:
- name: Set up Deno
uses: denoland/setup-deno@v2

- name: Test
run: deno task test

- name: Publish to JSR
run: deno publish --config javascript-sdk/deno.json
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
docs/
.DS_Store
deno.lock
**/cov/
docs/
coverage/
4 changes: 2 additions & 2 deletions javascript-sdk/deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"exclude": [".git", "coverage", "docs"],
"exclude": [".git", "coverage", "docs", "tests"],
"tasks": {
"ok": "deno lint && deno fmt --check"
"test": "deno test -A --clean"
},
"workspace": ["./logstf"]
}
23 changes: 23 additions & 0 deletions javascript-sdk/logstf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# logs.tf

The types and SDK that can interact with the (logs.tf api)[https://logs.tf/about].

## Install

Checkout the [jsr page](https://jsr.io/@tf2software/logstf) for more details.

### Examples

A simple example that can request the log json of a particular game:

```ts
const logJson = await getById("3750052");

console.log(logJson);
```

For more examples, see the [documentation on jsr](https://jsr.io/@tf2software/logstf/doc)

## License

Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
3 changes: 3 additions & 0 deletions javascript-sdk/logstf/api/logstf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ const getRawLogUrl = (id: string) => `http://logs.tf/logs/log_${id}.log.zip`;

/**
* The base URL of the for logs.tf
*
* @internal
*/
const logsBaseUrl = "https://logs.tf";

/**
* The logs API url
*
* @internal
*/
const logsApiUrl = `${logsBaseUrl}/api/v1`;

/**
* The logs upload url
*
* @internal
*/
const logsUploadUrl = `${logsBaseUrl}/upload`;
Expand Down
6 changes: 6 additions & 0 deletions javascript-sdk/logstf/api/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* Provides methods used to interact with the [logs.tf api](https://logs.tf/about)
*
* @example Fetching the JSON for a log
* ```ts
* const logJson = await getById("3750052");
*
* console.log(logJson);
* ```
* @module
*/

Expand Down
2 changes: 1 addition & 1 deletion javascript-sdk/logstf/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tf2software/logstf",
"version": "0.0.1",
"version": "0.0.2",
"exports": {
".": "./mod.ts",
"./api": "./mod.ts",
Expand Down
2 changes: 1 addition & 1 deletion javascript-sdk/logstf/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @module
*/

export * from "./types/mod.ts";
export * from "./api/mod.ts";
export * from "./types/mod.ts";
44 changes: 44 additions & 0 deletions javascript-sdk/logstf/tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getById } from "../mod.ts";
import { assertEquals, assertExists, assertObjectMatch } from "jsr:@std/assert";

Deno.test("Getting a valid log succeeds", async () => {
const log = await getById("3750052");

assertEquals(log.success, true);
assertExists(log.chat);
assertObjectMatch(log.info, {
map: "cp_metalworks_f5",
supplemental: true,
total_length: 932,
hasRealDamage: true,
hasWeaponDamage: true,
hasAccuracy: true,
hasHP: true,
hasHP_real: true,
hasHS: false,
hasHS_hit: false,
hasBS: false,
hasCP: true,
hasSB: false,
hasDT: true,
hasAS: true,
hasHR: true,
hasIntel: false,
AD_scoring: false,
notifications: [],
title: "na.serveme.tf #574912: RED vs BLU",
date: 1731040571,
uploader: {
id: "76561197960497430",
name: "Arie - VanillaTF2.org",
info: "LogsTF 2.6.0",
},
});
});

Deno.test("Getting an invalid log fails", async () => {
const log = await getById("999999999999999");

assertEquals(log.success, false);
assertEquals(log.error, "Log not found.");
});
19 changes: 19 additions & 0 deletions javascript-sdk/logstf/types/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* A chat message
*/
export type ChatMessage = {
/**
* The steam id of the player that said the message
*/
steamid: string;

/**
* The name of the player
*/
name: string;

/**
* The content of the message
*/
msg: string;
};
49 changes: 49 additions & 0 deletions javascript-sdk/logstf/types/classStats.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
/**
* Statistics for each type of class that the player played as
*/
export type ClassStats = {
/**
* The class that was played
*/
type: string;

/**
* The number of kills
*/
kills: number;

/**
* The number of assists
*/
assists: number;

/**
* The number of deaths
*/
deaths: number;

/**
* The total damage dealt
*/
dmg: number;

/**
* Statistics about the weapons used by the player
*/
weapon: {
[weaponName: string]: {
/**
* The number of kills with this weapon
*/
kills: number;

/**
* The amount of damage dealt by the weapon
*/
dmg: number;

/**
* The average damage with this weapon
*/
avg_dmg: number;

/**
* The total number of shots with this weapon
*/
shots: number;

/**
* The number of shots that hit another player
*/
hits: number;
};
};

/**
* The amount of time on this class
*/
total_time: number;
};
Loading

0 comments on commit 99e7b42

Please sign in to comment.