Skip to content

Commit

Permalink
chore(deps): update project dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Mar 27, 2024
1 parent b1dbf89 commit b17f6b5
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 116 deletions.
4 changes: 2 additions & 2 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.3",
"@tsconfig/svelte": "^5.0.4",
"@types/webextension-polyfill": "^0.10.7",
"@yd/config": "workspace:*",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"wxt": "^0.17.9"
Expand Down
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"@yd/ui": "workspace:*"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.1.1",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.4",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@yd/config": "workspace:*",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^5.2.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"format": "prettier --write ."
},
"devDependencies": {
"@hey-api/openapi-ts": "^0.29.0",
"@hey-api/openapi-ts": "^0.30.0",
"@yd/api": "workspace:*",
"@yd/config": "workspace:*",
"prettier": "^3.2.5",
Expand Down
45 changes: 25 additions & 20 deletions packages/client/src/generated/core/OpenAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { TConfig, TResult } from './types';
import type { TResult } from './types';

type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;
type Middleware<T> = (value: T) => T | Promise<T>;
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;

export class Interceptors<T> {
_fns: Middleware<T>[];

constructor() {
this._fns = [];
}

eject(fn: Middleware<T>) {
const index = this._fns.indexOf(fn);
if (index !== -1) {
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
}
}

use(fn: Middleware<T>) {
this._fns = [...this._fns, fn];
}
}

export type OpenAPIConfig = {
BASE: string;
Expand All @@ -15,6 +35,7 @@ export type OpenAPIConfig = {
USERNAME?: string | Resolver<string> | undefined;
VERSION: string;
WITH_CREDENTIALS: boolean;
interceptors: { request: Interceptors<RequestInit>; response: Interceptors<Response> };
};

export const OpenAPI: OpenAPIConfig = {
Expand All @@ -27,22 +48,6 @@ export const OpenAPI: OpenAPIConfig = {
TOKEN: undefined,
USERNAME: undefined,
VERSION: '1.0.0',
WITH_CREDENTIALS: false
};

export const mergeOpenApiConfig = <T extends TResult>(
config: OpenAPIConfig,
overrides: TConfig<T>
) => {
const merged = { ...config };
Object.entries(overrides)
.filter(([key]) => key.startsWith('_'))
.forEach(([key, value]) => {
const k = key.slice(1).toLocaleUpperCase() as keyof typeof merged;
if (merged.hasOwnProperty(k)) {
// @ts-ignore
merged[k] = value;
}
});
return merged;
WITH_CREDENTIALS: false,
interceptors: { request: new Interceptors(), response: new Interceptors() }
};
13 changes: 11 additions & 2 deletions packages/client/src/generated/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const sendRequest = async (
): Promise<Response> => {
const controller = new AbortController();

const request: RequestInit = {
let request: RequestInit = {
headers,
body: body ?? formData,
method: options.method,
Expand All @@ -206,6 +206,10 @@ export const sendRequest = async (
request.credentials = config.CREDENTIALS;
}

for (const fn of config.interceptors.request._fns) {
request = await fn(request);
}

onCancel(() => controller.abort());

return await fetch(url, request);
Expand Down Expand Up @@ -303,7 +307,12 @@ export const request = <T>(
const headers = await getHeaders(config, options);

if (!onCancel.isCancelled) {
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);

for (const fn of config.interceptors.response._fns) {
response = await fn(response);
}

const responseBody = await getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

Expand Down
4 changes: 2 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-tailwindcss": "^0.5.12",
"tailwindcss": "^3.4.1"
"prettier-plugin-tailwindcss": "^0.5.13",
"tailwindcss": "^3.4.3"
}
}
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"svelte": "^4.0.0"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.1.1",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.4",
"@sveltejs/package": "^2.3.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
Expand All @@ -44,7 +44,7 @@
"publint": "^0.2.7",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^5.2.6"
Expand Down
Loading

0 comments on commit b17f6b5

Please sign in to comment.