Skip to content

Commit

Permalink
feat(mocks-counterfact): create package, scripts, types, mocks (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
treyturner authored Oct 6, 2024
1 parent 61e351f commit e1cdeb2
Show file tree
Hide file tree
Showing 220 changed files with 4,833 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Monorepo for TypeScript packages related to [Artifacts MMO](https://artifactsmmo

## Packages

| Name | Folder | Description |
|--------------------------------------------------------------------------------------------------------|--------------------------------------|----------------------------------|
| [`@trey.turner/artifacts-api-client`](https://www.npmjs.com/package/@trey.turner/artifacts-api-client) | [`api-client`](packages/api-client/) | Typed and promisified API client |
| Folder | Name | Description |
|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
| [`api-client`](packages/api-client/) | [`@trey.turner/artifacts-api-client`](https://www.npmjs.com/package/@trey.turner/artifacts-api-client) | Typed and promisified API client in ESM |
| [`mocks-counterfact`](packages/mocks-counterfact/) | [`@trey.turner/artifacts-mocks-counterfact`](https://www.npmjs.com/package/@trey.turner/artifacts-mocks-counterfact) | Mocks & types generated from OpenAPI spec |
| [`sandbox`](packages/api-client/) | Not published | Code staging area |

## Tooling

Expand Down
20 changes: 19 additions & 1 deletion biome.json → biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,23 @@
"formatter": {
"trailingCommas": "none"
}
}
},
"overrides": [
{
"include": ["packages/mocks-counterfact/src/types.ts"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"correctness": {
"noUnusedVariables": "off"
},
"complexity": {
"noBannedTypes": "off"
}
}
}
}
]
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"@commitlint/config-conventional": "19.5.0",
"husky": "9.1.6"
},
"trustedDependencies": ["@biomejs/biome"]
"trustedDependencies": ["@biomejs/biome", "counterfact"]
}
18 changes: 4 additions & 14 deletions packages/api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
# ts-artifacts-api-client
# artifacts-api-client

A typed and promisified API client for [Artifacts MMO](https://artifactsmmo.com).
A typed and promisified API client for Artifacts MMO in ESM.

## Status

This is a new project in early development. Pull requests, issues, and suggestions are welcome. Use at your own risk; no warranty is expressed or implied.

API coverage is believed to be complete. Some amount of automated E2E testing passed against the game's production API at the time of last release, but changes to the game may cause breakage until this client can be updated.

Automated test coverage will be expanded in the future but isn't a priority at this time.

At this time, development is driven by the needs of my [CLI](https://github.com/treyturner/ts-artifacts-cli). I'm currently exploring approaches to game and client state management.

## Installation

Add as a dependency to your project's `package.json`:

```sh
user@dev:~/ts-artifacts-api-client$ bun add @trey.turner/artifacts-api-client
```

Then install using your package manager or runtime of choice, like [bun](https://bun.sh):

```sh
user@dev:~/ts-artifacts-api-client$ bun i
user@dev:~/some-project$ bun add @trey.turner/artifacts-api-client
```

## Configuration
Expand Down Expand Up @@ -58,7 +48,7 @@ When your required configuration is set into environment variables, you can use
import { ArtifactsApi } from '@trey.turner/artifacts-api-client';

const api = new ArtifactsApi();
// will logs response to console if configured as such
// will log response to console if configured as such
await api.info.meta.getServerStatus();
```

Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv";
import type { Config, Preferences, RecursivePartial } from "./types";
import { getCallerName, log, pp } from "./util";
import type { Config, RecursivePartial, Preferences } from "./types";

const { env } = process;

Expand Down
2 changes: 2 additions & 0 deletions packages/mocks-counterfact/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
test
3 changes: 3 additions & 0 deletions packages/mocks-counterfact/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# artifacts-mocks-counterfact

Mocks of Artifacts MMO API generated from their published OpenAPI specification using counterfact.
21 changes: 21 additions & 0 deletions packages/mocks-counterfact/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["../../biome.jsonc"],
"overrides": [
{
"include": ["src/types.ts"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"correctness": {
"noUnusedVariables": "off"
},
"complexity": {
"noBannedTypes": "off"
}
}
}
}
]
}
40 changes: 40 additions & 0 deletions packages/mocks-counterfact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@trey.turner/artifacts-mocks-counterfact",
"version": "0.0.1",
"module": "index.ts",
"main": "dist/index.js",
"types": "dist/types.d.ts",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/treyturner/ts-artifacts.git"
},
"scripts": {
"build": "tsc -p src/tsconfig.json",
"check": "bun run --silent lint && bun run --silent format && bun run --silent typecheck",
"check:fix": "bun run --silent lint:fix && bun run --silent format:fix && bun run --silent typecheck",
"clean": "bun run --silent clean:build && bun run --silent clean:deps",
"clean:build": "rm -rf dist",
"clean:deps": "rm -rf node_modules bun.lockb",
"format": "biome format src/ test/",
"format:fix": "biome format --write src/ test/",
"generate": "bun run counterfact -g https://api.artifactsmmo.com/openapi.json src",
"lint": "biome lint --error-on-warnings src/ test/",
"lint:fix": "biome lint --error-on-warnings --fix src/ test/",
"open": "bun run counterfact -o https://api.artifactsmmo.com/openapi.json src",
"repl": "bun run counterfact -wrs https://api.artifactsmmo.com/openapi.json src",
"start": "bun run watch",
"typecheck": "tsc -p src/tsconfig.json && tsc --noEmit -p test/tsconfig.json",
"watch": "bun run counterfact -ws https://api.artifactsmmo.com/openapi.json src"
},
"dependencies": {
"counterfact": "1.1.0"
},
"devDependencies": {
"@types/bun": "latest",
"typescript": "5.6.2"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
1 change: 1 addition & 0 deletions packages/mocks-counterfact/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache
11 changes: 11 additions & 0 deletions packages/mocks-counterfact/src/routes/_.context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* This is the default context for Counterfact.
*
* It defines the context object in the REPL
* and the $.context object in the code.
*
* Add properties and methods to suit your needs.
*
* See https://counterfact.dev/docs/usage.html#working-with-state-the-codecontextcode-object-and-codecontexttscode
*/
export class Context {}
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/accounts/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../types/paths/accounts/create.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/achievements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/achievements.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/achievements/{code}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/achievements/{code}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/characters.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/characters/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../types/paths/characters/create.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/characters/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../types/paths/characters/delete.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/characters/{name}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/characters/{name}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../../types/paths/characters/{name}/achievements.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/events.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/ge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/ge.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/ge/{code}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/ge/{code}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/index.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/items.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/items/{code}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/items/{code}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/leaderboard.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/maps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/maps.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/maps/{x}/{y}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../../types/paths/maps/{x}/{y}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/monsters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../types/paths/monsters.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/monsters/{code}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/monsters/{code}.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/my/bank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/my/bank.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/my/bank/items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../../types/paths/my/bank/items.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/my/change_password.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../types/paths/my/change_password.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/my/characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/my/characters.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
5 changes: 5 additions & 0 deletions packages/mocks-counterfact/src/routes/my/logs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_GET } from "../../types/paths/my/logs.types.js";

export const GET: HTTP_GET = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../types/paths/my/{name}/action/bank/buy_expansion.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../types/paths/my/{name}/action/bank/deposit.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../../types/paths/my/{name}/action/bank/deposit/gold.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../types/paths/my/{name}/action/bank/withdraw.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../../types/paths/my/{name}/action/bank/withdraw/gold.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../types/paths/my/{name}/action/crafting.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../types/paths/my/{name}/action/delete.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../types/paths/my/{name}/action/equip.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../types/paths/my/{name}/action/fight.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../types/paths/my/{name}/action/gathering.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../types/paths/my/{name}/action/ge/buy.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { HTTP_POST } from "../../../../../types/paths/my/{name}/action/ge/sell.types.js";

export const POST: HTTP_POST = ($) => {
return $.response[200].random();
};
Loading

0 comments on commit e1cdeb2

Please sign in to comment.