Skip to content

Commit 0e81f08

Browse files
authored
refactor: declare BreezeRuntime by global augmentation (#13)
1 parent c27c88c commit 0e81f08

8 files changed

Lines changed: 99 additions & 110 deletions

File tree

.github/workflows/publish.yml

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

deno.jsonc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"$schema": "https://jsr.io/schema/config-file.v1.json",
32
"name": "@byzanteam/breeze-js",
4-
"version": "0.4.0",
3+
"version": "0.5.0",
4+
"license": "MIT",
55
"compilerOptions": {
66
"strict": true,
77
"useUnknownInCatchVariables": true,
@@ -11,19 +11,25 @@
1111
]
1212
},
1313
"exclude": [
14-
".git"
14+
".git",
15+
".github"
1516
],
1617
"exports": {
1718
".": "./lib/runtime.ts",
1819
"./runtime": "./lib/runtime.ts",
1920
"./url": "./lib/url.ts",
2021
"./types": "./types/global.d.ts"
2122
},
22-
"license": "MIT",
23-
"publish": {
24-
"exclude": [
25-
".github"
26-
]
23+
"imports": {
24+
"@std/assert": "jsr:@std/assert@^1.0.13",
25+
"@std/testing": "jsr:@std/testing@^1.0.13"
26+
},
27+
"lint": {
28+
"rules": {
29+
"exclude": [
30+
"no-slow-types"
31+
]
32+
}
2733
},
2834
"tasks": {
2935
"check": "deno fmt && deno lint && deno task check:types && deno task test",

dev_deps.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { getEnv, getEnvOrThrow } from "../lib/runtime.ts";
2-
import { assertEquals, assertThrows, describe, it } from "../dev_deps.ts";
1+
import { assertEquals, assertThrows } from "@std/assert";
2+
import { describe, it } from "@std/testing/bdd";
3+
import { getEnv, getEnvOrThrow } from "./runtime.ts";
34

45
describe("Runtime Module", () => {
56
it("getEnv should return the value of an environment variable", () => {

tests/url_test.ts renamed to lib/url.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { buildUrl, getBaseUrl, joinPath } from "../lib/url.ts";
2-
import { assertEquals, describe, it } from "../dev_deps.ts";
3-
import { setupEnv } from "./testing_util.ts";
1+
import { assertEquals } from "@std/assert";
2+
import { describe, it } from "@std/testing/bdd";
3+
import { buildUrl, getBaseUrl, joinPath } from "./url.ts";
4+
import { setupEnv } from "../tests/env.ts";
45

56
describe("buildUrl function", () => {
67
const { setEnv } = setupEnv();
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { afterEach, beforeEach, type Stub, stub } from "../dev_deps.ts";
1+
import { afterEach, beforeEach } from "@std/testing/bdd";
2+
import { type Stub, stub } from "@std/testing/mock";
23
import { _internals } from "../lib/runtime.ts";
34

45
let envs: {

types/global.d.ts

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,88 @@
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-
}
1+
declare global {
2+
namespace BreezeRuntime {
3+
export interface DeploymentInfo {
4+
projectId: string;
5+
environmentId: string;
6+
functionId: string;
7+
}
128

13-
/**
14-
* A JWT token generated by Breeze to authorize plugin or workflow requests.
15-
*/
16-
export type Token = string;
9+
export interface Plugin {
10+
id: string;
11+
endpoint: string;
12+
}
1713

18-
export interface TokenOptions {
1914
/**
20-
* The instance name of plugin.
15+
* A JWT token generated by Breeze to authorize plugin or workflow requests.
2116
*/
22-
plugin?: string;
17+
export type Token = string;
18+
19+
export interface TokenOptions {
20+
/**
21+
* The instance name of plugin.
22+
*/
23+
plugin?: string;
24+
}
2325
}
2426

25-
/**
26-
* Retrieves the current deployment information.
27-
* @returns The deployment information of the current function.
28-
*/
29-
export function getDeploymentInfo(): DeploymentInfo;
27+
interface BreezeRuntime {
28+
/**
29+
* Generates an authentication token for a plugin or workflow request.
30+
* @param opts - Optional settings for the token generation.
31+
* @returns A JWT token.
32+
*/
33+
generateToken(opts?: BreezeRuntime.TokenOptions): BreezeRuntime.Token;
3034

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;
35+
/**
36+
* Retrieves the current deployment information.
37+
* @returns The deployment information of the current function.
38+
*/
39+
getDeploymentInfo(): BreezeRuntime.DeploymentInfo;
3740

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;
41+
/**
42+
* Retrieves a registered plugin by its name.
43+
* @param plugin - The name of the plugin.
44+
* @returns The plugin instance if found, otherwise `null`.
45+
*/
46+
getPlugin(plugin: string): BreezeRuntime.Plugin | null;
4447

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>;
48+
/**
49+
* Performs a fetch request to the specified plugin.
50+
* @param plugin - The name of the plugin.
51+
* @returns A `Promise` resolving to the response.
52+
*/
53+
pluginFetch(plugin: string): Promise<Response>;
5154

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>;
55+
/**
56+
* Performs a fetch request to a specific path on the specified plugin.
57+
* @param plugin - The name of the plugin.
58+
* @param path - The request path.
59+
* @returns A `Promise` resolving to the response.
60+
*/
61+
pluginFetch(plugin: string, path: string): 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+
pluginFetch(plugin: string, opts: RequestInit): Promise<Response>;
6270

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>;
71+
/**
72+
* Performs a fetch request to a specific path on a plugin with custom request options.
73+
* @param plugin - The name of the plugin.
74+
* @param path - The request path.
75+
* @param opts - The fetch request options.
76+
* @returns A `Promise` resolving to the response.
77+
*/
78+
pluginFetch(
79+
plugin: string,
80+
path: string,
81+
opts: RequestInit,
82+
): Promise<Response>;
83+
}
7384

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>;
85+
const BreezeRuntime: BreezeRuntime;
8686
}
87+
88+
export {};

types/global_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type Has,
44
type IsExact,
55
type IsNullable,
6-
} from "../dev_deps.ts";
6+
} from "@std/testing/types";
77

88
{
99
type Result = ReturnType<typeof BreezeRuntime.getDeploymentInfo>;

0 commit comments

Comments
 (0)