Skip to content

Commit 40ddbc7

Browse files
committed
Initial commit
0 parents  commit 40ddbc7

19 files changed

Lines changed: 1177 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
workflow_call:
6+
7+
jobs:
8+
deno:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: denoland/setup-deno@v1
13+
with:
14+
deno-version: v1.x
15+
16+
- name: Code Style
17+
run: deno fmt --check
18+
19+
- name: Linting
20+
run: deno lint
21+
22+
- name: Type Check
23+
run: deno check scripts/*.ts *.ts
24+
25+
- name: Tests
26+
run: |
27+
deno test --coverage=cov/
28+
deno coverage cov/
29+
30+
npm:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: denoland/setup-deno@v1
35+
with:
36+
deno-version: v1.x
37+
38+
- run: deno task build

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/npm
3+
*.lcov
4+
/cov

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

deno.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.1.0",
3+
"exports": "./mod.ts",
4+
"name": "@exceptionless/fetchclient",
5+
"tasks": {
6+
"build": "deno run -A scripts/build.ts",
7+
"publish": "deno run -A scripts/publish.ts"
8+
},
9+
"imports": {
10+
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
11+
"@std/assert": "jsr:@std/[email protected]",
12+
"@std/path": "jsr:@std/path@^0.221.0"
13+
},
14+
"exclude": [
15+
"npm"
16+
]
17+
}

deno.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

license

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Exceptionless
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

mod.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FetchClient } from "./src/FetchClient.ts";
2+
3+
export * from "./src/FetchClient.ts";
4+
export type { FetchClientResponse } from "./src/FetchClientResponse.ts";
5+
export { ProblemDetails } from "./src/ProblemDetails.ts";
6+
export type { RequestOptions } from "./src/RequestOptions.ts";
7+
export type { FetchClientMiddleware } from "./src/FetchClientMiddleware.ts";
8+
export type { FetchClientContext } from "./src/FetchClientContext.ts";
9+
10+
/**
11+
* A global singleton instance of the FetchClient.
12+
*/
13+
export const instance: FetchClient = new FetchClient();

readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- deno-fmt-ignore-file -->
2+
# FetchClient [![CI](https://github.com/exceptionless/fetchclient/workflows/CI/badge.svg)](https://github.com/exceptionless/fetchclient/actions?query=workflow%3ACI)
3+
4+
* Wrap fetch and make it easier to use
5+
* Add middleware support
6+
* Add Problem Details support
7+
8+
## Install
9+
10+
```
11+
$ npm install --save @exceptionless/fetchclient
12+
```
13+
14+
## Usage
15+
16+
```ts
17+
import { FetchClient } from '@exceptionless/fetchclient';
18+
```
19+
20+
## License
21+
22+
MIT © [Exceptionless](https://exceptionless.com)

scripts/build.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { build, emptyDir } from "@deno/dnt";
2+
3+
await emptyDir("./npm");
4+
5+
await build({
6+
entryPoints: ["./mod.ts"],
7+
outDir: "./npm",
8+
shims: {
9+
deno: true,
10+
},
11+
12+
declaration: "separate",
13+
scriptModule: "cjs",
14+
typeCheck: "both",
15+
test: true,
16+
17+
importMap: "deno.json",
18+
19+
package: {
20+
name: "fetchclient",
21+
version: Deno.args[0],
22+
repository: "exceptionless/fetchclient",
23+
license: "Apache-2.0",
24+
description:
25+
"A simple fetch client with middleware support for Deno and the browser.",
26+
author: {
27+
name: "Eric J. Smith",
28+
29+
url: "https://exceptionless.com",
30+
},
31+
keywords: [
32+
"Fetch",
33+
"Middleware",
34+
"ProblemDetails",
35+
"Problem",
36+
],
37+
},
38+
39+
compilerOptions: {
40+
target: "ES2022",
41+
lib: ["ES2022", "WebWorker"],
42+
},
43+
44+
async postBuild() {
45+
await Deno.copyFile("license", "npm/license");
46+
await Deno.copyFile("readme.md", "npm/readme.md");
47+
},
48+
});

scripts/publish.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// deno-lint-ignore-file no-deprecated-deno-api
2+
import { resolve } from "@std/path";
3+
import { assert } from "@std/assert";
4+
5+
import * as semver from "https://deno.land/x/[email protected]/mod.ts";
6+
7+
type Options = Parameters<typeof Deno.run>[0];
8+
async function run(label: string, options: Options) {
9+
const p = await Deno.run(options).status();
10+
assert(p.code === 0, label);
11+
}
12+
13+
const version = semver.valid(Deno.args[0]);
14+
assert(version, "Invalid version!");
15+
16+
const file = resolve("./deno.json");
17+
const Config = JSON.parse(await Deno.readTextFile(file));
18+
19+
await run("build npm package", {
20+
cmd: ["deno", "task", "build", version],
21+
});
22+
23+
Config.version = version;
24+
const contents = JSON.stringify(Config, null, 2);
25+
await Deno.writeTextFile(file, contents);
26+
27+
// prevent CI error
28+
await run("deno fmt", {
29+
cmd: ["deno", "fmt", file],
30+
});
31+
32+
await run("publish npm package", {
33+
cmd: ["npm", "publish"],
34+
cwd: resolve("npm"),
35+
});
36+
37+
await run("publish jsr package", {
38+
cmd: ["deno", "publish", "--allow-dirty"],
39+
});
40+
41+
await run("git add", {
42+
cmd: ["git", "add", file],
43+
});
44+
45+
await run("git commit", {
46+
cmd: ["git", "commit", "-m", version],
47+
});
48+
49+
await run("git tag", {
50+
cmd: ["git", "tag", version],
51+
});
52+
53+
await run("git push", {
54+
cmd: ["git", "push", "--tags"],
55+
});

0 commit comments

Comments
 (0)