Skip to content

Commit 6a8b7c3

Browse files
authored
chore: publish to jsr (#12)
1 parent 905708c commit 6a8b7c3

11 files changed

Lines changed: 145 additions & 96 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,22 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
deno: ["canary", "v1.x"]
17+
deno: ["canary", "v2.x"]
1818

1919
steps:
2020
- name: Checkout repo
2121
uses: actions/checkout@v4
2222

2323
- name: Setup Deno
24-
uses: denoland/setup-deno@v1
24+
uses: denoland/setup-deno@v2
2525
with:
2626
deno-version: ${{ matrix.deno }}
2727

28-
- name: Verify formatting
29-
run: deno fmt --check
30-
31-
- name: Run linter
32-
run: deno lint
33-
3428
- name: Spell-check
35-
if: matrix.deno == 'v1.x'
29+
if: matrix.deno == 'v2.x'
3630
uses: crate-ci/typos@master
3731

38-
- name: Type check project
39-
run: deno task check:types
40-
41-
- name: Run tests
42-
run: deno task test
32+
- run: deno fmt
33+
- run: deno lint
34+
- run: deno task check:types
35+
- run: deno task test

.github/workflows/publish.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- run: npx jsr publish

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
# TypeScript type definitions for BreezeRuntime
22

3-
## Usage
4-
5-
Add types into your deno config file(eg: `deno.jsonc`):
6-
7-
```jsonc
8-
{
9-
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
10-
"compilerOptions": {
11-
"types": [
12-
// add types of BreezeRuntime
13-
"https://cdn.jsdelivr.net/gh/Byzanteam/breeze-js@latest/mod.d.ts"
14-
]
15-
}
16-
}
17-
```
3+
[![JSR](https://jsr.io/badges/@byzanteam/breeze-js)](https://jsr.io/@byzanteam/breeze-js)

deno.jsonc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
{
2-
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
2+
"$schema": "https://jsr.io/schema/config-file.v1.json",
3+
"name": "@byzanteam/breeze-js",
4+
"version": "0.1.0",
35
"compilerOptions": {
46
"strict": true,
57
"useUnknownInCatchVariables": true,
68
"noImplicitOverride": true,
79
"types": [
8-
"./mod.d.ts"
10+
"./types/global.d.ts"
911
]
1012
},
1113
"exclude": [
1214
".git"
1315
],
16+
"exports": {
17+
".": "./lib/runtime.ts",
18+
"./runtime": "./lib/runtime.ts",
19+
"./url": "./lib/url.ts",
20+
"./types": "./types/global.d.ts"
21+
},
22+
"license": "MIT",
23+
"publish": {
24+
"exclude": [
25+
".github"
26+
]
27+
},
1428
"tasks": {
15-
"test": "deno check types_test.ts",
16-
"check:types": "deno check **/*.ts",
17-
"check": "deno fmt --check && deno lint && deno task check:types && deno task test"
29+
"check": "deno fmt && deno lint && deno task check:types && deno task test",
30+
"check:types": "deno check lib/**/*.ts && deno check types/global_test.ts",
31+
"test": "deno test -A"
1832
}
1933
}

dev_deps.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export * from "https://deno.land/std@0.218.0/testing/bdd.ts";
2-
export * from "https://deno.land/std@0.218.0/assert/mod.ts";
3-
export * from "https://deno.land/std@0.208.0/testing/mock.ts";
1+
export * from "jsr:@std/assert";
2+
export * from "jsr:@std/testing/bdd";
3+
export * from "jsr:@std/testing/mock";
4+
export * from "jsr:@std/testing/types";

lib/runtime.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
export const isDeno = typeof Deno !== "undefined";
2-
export const isBreezeRuntime = typeof BreezeRuntime !== "undefined";
3-
41
export function getEnv(key: string): string | undefined {
5-
return Deno.env.get(key);
2+
return _internals.doGetEnv(key);
63
}
74

85
export function getEnvOrThrow(key: string): string {

mod.d.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/runtime_test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getEnv, getEnvOrThrow } from "../lib/runtime.ts";
2-
import { assertEquals, assertRejects, describe, it } from "../dev_deps.ts";
2+
import { assertEquals, assertThrows, describe, it } from "../dev_deps.ts";
33

44
describe("Runtime Module", () => {
55
it("getEnv should return the value of an environment variable", () => {
@@ -10,10 +10,8 @@ describe("Runtime Module", () => {
1010
it("getEnvOrThrow should throw if the environment variable is not set", () => {
1111
const key = "NON_EXISTENT_VAR";
1212

13-
assertRejects(
14-
async () => {
15-
await getEnvOrThrow(key);
16-
},
13+
assertThrows(
14+
() => getEnvOrThrow(key),
1715
Error,
1816
`Missing environment variable: ${key}`,
1917
);

tests/testing_util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, Stub, stub } from "../dev_deps.ts";
1+
import { afterEach, beforeEach, type Stub, stub } from "../dev_deps.ts";
22
import { _internals } from "../lib/runtime.ts";
33

44
let envs: {
@@ -26,5 +26,6 @@ export function setupEnv() {
2626
function setEnv(key: string, value: string) {
2727
envs.push({ key, value });
2828
}
29+
2930
return { setEnv };
3031
}

types/global.d.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
declare namespace BreezeRuntime {
2+
export interface DeploymentInfo {
3+
projectId: string;
4+
environmentId: string;
5+
functionId: string;
6+
}
7+
8+
export interface Plugin {
9+
id: string;
10+
endpoint: string;
11+
}
12+
13+
/**
14+
* A JWT token generated by Breeze to authorize plugin or workflow requests.
15+
*/
16+
export type Token = string;
17+
18+
export interface TokenOptions {
19+
/**
20+
* The instance name of plugin.
21+
*/
22+
plugin?: string;
23+
}
24+
25+
/**
26+
* Retrieves the current deployment information.
27+
* @returns The deployment information of the current function.
28+
*/
29+
export function getDeploymentInfo(): DeploymentInfo;
30+
31+
/**
32+
* Retrieves a registered plugin by its name.
33+
* @param plugin - The name of the plugin.
34+
* @returns The plugin instance if found, otherwise `null`.
35+
*/
36+
export function getPlugin(plugin: string): Plugin | null;
37+
38+
/**
39+
* Generates an authentication token for a plugin or workflow request.
40+
* @param opts - Optional settings for the token generation.
41+
* @returns A JWT token.
42+
*/
43+
export function generateToken(opts?: TokenOptions): Token;
44+
45+
/**
46+
* Performs a fetch request to the specified plugin.
47+
* @param plugin - The name of the plugin.
48+
* @returns A `Promise` resolving to the response.
49+
*/
50+
export function pluginFetch(plugin: string): Promise<Response>;
51+
52+
/**
53+
* Performs a fetch request to a specific path on the specified plugin.
54+
* @param plugin - The name of the plugin.
55+
* @param path - The request path.
56+
* @returns A `Promise` resolving to the response.
57+
*/
58+
export function pluginFetch(
59+
plugin: string,
60+
path: string,
61+
): Promise<Response>;
62+
63+
/**
64+
* Performs a fetch request to a plugin with custom request options.
65+
* @param plugin - The name of the plugin.
66+
* @param opts - The fetch request options.
67+
* @returns A `Promise` resolving to the response.
68+
*/
69+
export function pluginFetch(
70+
plugin: string,
71+
opts: RequestInit,
72+
): Promise<Response>;
73+
74+
/**
75+
* Performs a fetch request to a specific path on a plugin with custom request options.
76+
* @param plugin - The name of the plugin.
77+
* @param path - The request path.
78+
* @param opts - The fetch request options.
79+
* @returns A `Promise` resolving to the response.
80+
*/
81+
export function pluginFetch(
82+
plugin: string,
83+
path: string,
84+
opts: RequestInit,
85+
): Promise<Response>;
86+
}

0 commit comments

Comments
 (0)