@data-eden/network
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -10,6 +10,5 @@ import { | ||
} from 'vitest'; | ||
import * as http from 'http'; | ||
import type * as http from 'http'; | ||
import { | ||
buildFetch, | ||
import type { | ||
Middleware, | ||
@@ -19,2 +18,3 @@ MiddlewareMetadata, | ||
} from '@data-eden/network'; | ||
import { buildFetch } from '@data-eden/network'; | ||
import { createServer } from '@data-eden/shared-test-utilities'; | ||
@@ -478,2 +478,28 @@ | ||
test('should be able to return cached data', async () => { | ||
expect.assertions(2); | ||
async function cachingMiddleware( | ||
request: Request, | ||
next: (request: Request) => Promise<Response> | ||
): Promise<Response> { | ||
const response = new Response( | ||
JSON.stringify({ status: 'cached-success' }), | ||
{ status: 200, headers: { 'Content-Type': 'application/json' } } | ||
); | ||
return response; | ||
} | ||
const fetch = buildFetch([cachingMiddleware]); | ||
const response = await fetch(server.buildUrl('/analytics')); | ||
expect(response.status).toEqual(200); | ||
expect(await response.json()).toMatchInlineSnapshot(` | ||
{ | ||
"status": "cached-success", | ||
} | ||
`); | ||
}); | ||
test('can read and mutate request headers', async function () { | ||
@@ -480,0 +506,0 @@ expect.assertions(2); |
@@ -11,2 +11,3 @@ import { | ||
import type { FetchDebugInfo } from '@data-eden/network'; | ||
import { | ||
@@ -18,3 +19,2 @@ buildFetch, | ||
getPendingRequestState, | ||
FetchDebugInfo, | ||
} from '@data-eden/network'; | ||
@@ -26,3 +26,3 @@ | ||
import * as http from 'http'; | ||
import type * as http from 'http'; | ||
@@ -29,0 +29,0 @@ import { fileURLToPath } from 'url'; |
@@ -1,2 +0,1 @@ | ||
export type Fetch = typeof fetch; | ||
export type NormalizedFetch = (request: Request) => Promise<Response>; | ||
@@ -12,3 +11,3 @@ export interface MiddlewareMetadata { | ||
*/ | ||
fetch: Fetch; | ||
fetch: typeof fetch; | ||
} | ||
@@ -44,3 +43,3 @@ export type Middleware = ( | ||
*/ | ||
fetch: Fetch; | ||
fetch: typeof fetch; | ||
} | ||
@@ -55,3 +54,3 @@ /** | ||
*/ | ||
export declare function buildFetch(middlewares: Middleware[], options?: BuildFetchOptions): Fetch; | ||
export declare function buildFetch(middlewares: Middleware[], options?: BuildFetchOptions): typeof fetch; | ||
//# sourceMappingURL=fetch.d.ts.map |
export { buildFetch } from './fetch.js'; | ||
export { hasPendingRequests, getPendingRequestState, default as SettledTrackingMiddleware, requestsCompleted, } from './settled-tracking-middleware.js'; | ||
export type { FetchDebugInfo, RequestsCompletedOptions, } from './settled-tracking-middleware.js'; | ||
export type { Middleware, MiddlewareMetadata, NormalizedFetch, } from './fetch.js'; | ||
export type { Middleware, MiddlewareMetadata, NormalizedFetch, BuildFetchOptions, } from './fetch.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,3 @@ | ||
import type { Fetch, MiddlewareMetadata, NormalizedFetch } from './fetch.js'; | ||
import type { MiddlewareMetadata, NormalizedFetch } from './fetch.js'; | ||
type Fetch = typeof fetch; | ||
/** | ||
@@ -125,2 +126,3 @@ Debug information that is exposed via `getPendingRequestState(...)`. | ||
export default function SettledTrackingMiddleware(request: Request, next: NormalizedFetch, metadata: MiddlewareMetadata): Promise<Response>; | ||
export {}; | ||
//# sourceMappingURL=settled-tracking-middleware.d.ts.map |
{ | ||
"name": "@data-eden/network", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -28,2 +28,3 @@ "type": "git", | ||
"scripts": { | ||
"build": "tsc --build", | ||
"test": "vitest run" | ||
@@ -33,3 +34,3 @@ }, | ||
"devDependencies": { | ||
"@data-eden/shared-test-utilities": "0.4.0", | ||
"@data-eden/shared-test-utilities": "0.5.0", | ||
"cross-fetch": "^3.1.5" | ||
@@ -36,0 +37,0 @@ }, |
@@ -1,3 +0,1 @@ | ||
export type Fetch = typeof fetch; | ||
export type NormalizedFetch = (request: Request) => Promise<Response>; | ||
@@ -14,3 +12,3 @@ | ||
*/ | ||
fetch: Fetch; | ||
fetch: typeof fetch; | ||
} | ||
@@ -50,3 +48,3 @@ | ||
*/ | ||
fetch: Fetch; | ||
fetch: typeof fetch; | ||
} | ||
@@ -69,3 +67,3 @@ | ||
options?: BuildFetchOptions | ||
): Fetch { | ||
): typeof fetch { | ||
if (typeof fetch === 'undefined') { | ||
@@ -78,3 +76,3 @@ throw new Error( | ||
let result: Fetch; | ||
let result: typeof fetch; | ||
@@ -81,0 +79,0 @@ const curriedMiddlewares: NormalizedFetch = [...middlewares] |
@@ -18,2 +18,3 @@ export { buildFetch } from './fetch.js'; | ||
NormalizedFetch, | ||
BuildFetchOptions, | ||
} from './fetch.js'; |
@@ -1,3 +0,5 @@ | ||
import type { Fetch, MiddlewareMetadata, NormalizedFetch } from './fetch.js'; | ||
import type { MiddlewareMetadata, NormalizedFetch } from './fetch.js'; | ||
type Fetch = typeof fetch; | ||
/** | ||
@@ -4,0 +6,0 @@ Debug information that is exposed via `getPendingRequestState(...)`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
311893
1461
3