Skip to content

Commit

Permalink
chore: fixed newly arisen type errors
Browse files Browse the repository at this point in the history
in particular, switched dependency is-subset for newer, is-subset-of library
  • Loading branch information
wheresrhys committed Jul 24, 2024
1 parent 70096ae commit 9e0bc09
Show file tree
Hide file tree
Showing 18 changed files with 427 additions and 415 deletions.
687 changes: 350 additions & 337 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"docs"
],
"scripts": {
"lint": "eslint --cache --fix --ext .js,.cjs .",
"lint": "eslint --cache --fix --ext .js,.cjs",
"lint:ci": "eslint --ext .js,.cjs .",
"prettier": "prettier --cache --write *.md \"./**/*.md\"",
"prettier:ci": "prettier *.md \"./**/*.md\"",
Expand Down Expand Up @@ -76,7 +76,7 @@
"npm run lint"
],
"packages/**/*.js": [
"npm run types:check"
"npm run types:check"
],
"**/*.md":[
"npm run prettier"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"dequal": "^2.0.3",
"globrex": "^0.1.2",
"is-subset": "^0.1.1",
"is-subset-of": "^3.1.10",
"querystring": "^0.2.1",
"regexparam": "^3.0.0"
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/CallHistory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@type-check
/** @typedef {import('./Route').RouteConfig} RouteConfig */
/** @typedef {import('./Route').RouteName} RouteName */
/** @typedef {import('./RequestUtils').NormalizedRequestOptions} NormalizedRequestOptions */
/** @typedef {import('./Matchers').RouteMatcher} RouteMatcher */
/** @typedef {import('./FetchMock').FetchMockConfig} FetchMockConfig */
/** @typedef {import('./Route.js').RouteConfig} RouteConfig */
/** @typedef {import('./Route.js').RouteName} RouteName */
/** @typedef {import('./RequestUtils.js').NormalizedRequestOptions} NormalizedRequestOptions */
/** @typedef {import('./Matchers.js').RouteMatcher} RouteMatcher */
/** @typedef {import('./FetchMock.js').FetchMockConfig} FetchMockConfig */
import { createCallLogFromUrlAndOptions } from './RequestUtils.js';
import { isUrlMatcher } from './Matchers.js';
import Route from './Route.js';
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/FetchMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Router from './Router.js';
import Route from './Route.js';
import CallHistory from './CallHistory.js';
import * as requestUtils from './RequestUtils.js';
/** @typedef {import('./Router').RouteMatcher} RouteMatcher */
/** @typedef {import('./Route').RouteName} RouteName */
/** @typedef {import('./Route').UserRouteConfig} UserRouteConfig */
/** @typedef {import('./Router').RouteResponse} RouteResponse */
/** @typedef {import('./Matchers').MatcherDefinition} MatcherDefinition */
/** @typedef {import('./CallHistory').CallLog} CallLog */
/** @typedef {import('./Route').RouteResponseFunction} RouteResponseFunction */
/** @typedef {import('./Router.js').RouteMatcher} RouteMatcher */
/** @typedef {import('./Route.js').RouteName} RouteName */
/** @typedef {import('./Route.js').UserRouteConfig} UserRouteConfig */
/** @typedef {import('./Router.js').RouteResponse} RouteResponse */
/** @typedef {import('./Matchers.js').MatcherDefinition} MatcherDefinition */
/** @typedef {import('./CallHistory.js').CallLog} CallLog */
/** @typedef {import('./Route.js').RouteResponseFunction} RouteResponseFunction */

/**
* @typedef FetchMockGlobalConfig
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/Matchers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@type-check
/** @typedef {import('./Route').RouteConfig} RouteConfig */
/** @typedef {import('./CallHistory').CallLog} CallLog */
/** @typedef {import('./Route.js').RouteConfig} RouteConfig */
/** @typedef {import('./CallHistory.js').CallLog} CallLog */
import glob from 'globrex';
import * as regexparam from 'regexparam';
import querystring from 'querystring';
import isSubset from 'is-subset';
import { isSubsetOf } from 'is-subset-of';
import { dequal as isEqual } from 'dequal';
import {
normalizeHeaders,
Expand Down Expand Up @@ -177,8 +177,8 @@ const getBodyMatcher = (route) => {
return (
sentBody &&
(route.matchPartialBody
? isSubset(sentBody, expectedBody)
: isEqual(sentBody, expectedBody))
? isSubsetOf(expectedBody, sentBody)
: isEqual(expectedBody, sentBody))
);
};
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/RequestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const protocolRelativeUrlRX = new RegExp('^//', 'i');
*/

/** @typedef {RequestInit | (RequestInit & DerivedRequestOptions) } NormalizedRequestOptions */
/** @typedef {import('./CallHistory').CallLog} CallLog */
/** @typedef {import('./CallHistory.js').CallLog} CallLog */

/**
* @param {string | string | URL} url
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { builtInMatchers } from './Matchers.js';
import statusTextMap from './StatusTextMap.js';

/** @typedef {import('./Matchers').RouteMatcher} RouteMatcher */
/** @typedef {import('./CallHistory').CallLog} CallLog */
/** @typedef {import('./Matchers').RouteMatcherFunction} RouteMatcherFunction */
/** @typedef {import('./Matchers').RouteMatcherUrl} RouteMatcherUrl */
/** @typedef {import('./Matchers').MatcherDefinition} MatcherDefinition */
/** @typedef {import('./FetchMock').FetchMockGlobalConfig} FetchMockGlobalConfig */
/** @typedef {import('./FetchMock').FetchImplementations} FetchImplementations */
/** @typedef {import('./Matchers.js').RouteMatcher} RouteMatcher */
/** @typedef {import('./CallHistory.js').CallLog} CallLog */
/** @typedef {import('./Matchers.js').RouteMatcherFunction} RouteMatcherFunction */
/** @typedef {import('./Matchers.js').RouteMatcherUrl} RouteMatcherUrl */
/** @typedef {import('./Matchers.js').MatcherDefinition} MatcherDefinition */
/** @typedef {import('./FetchMock.js').FetchMockGlobalConfig} FetchMockGlobalConfig */
/** @typedef {import('./FetchMock.js').FetchImplementations} FetchImplementations */

/**
* @typedef UserRouteConfig
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/Router.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//@type-check
import Route from './Route.js';
import { isUrlMatcher, isFunctionMatcher } from './Matchers.js';
/** @typedef {import('./Route').UserRouteConfig} UserRouteConfig */
/** @typedef {import('./Route').RouteConfig} RouteConfig */
/** @typedef {import('./Route').RouteResponse} RouteResponse */
/** @typedef {import('./Route').RouteResponseData} RouteResponseData */
/** @typedef {import('./Route').RouteResponseObjectData} RouteResponseObjectData */
/** @typedef {import('./Route').RouteResponseConfig} RouteResponseConfig */
/** @typedef {import('./Route').RouteResponseFunction} RouteResponseFunction */
/** @typedef {import('./Matchers').RouteMatcher} RouteMatcher */
/** @typedef {import('./FetchMock').FetchMockConfig} FetchMockConfig */
/** @typedef {import('./FetchMock')} FetchMock */
/** @typedef {import('./CallHistory').CallLog} CallLog */
/** @typedef {import('./Route.js').UserRouteConfig} UserRouteConfig */
/** @typedef {import('./Route.js').RouteConfig} RouteConfig */
/** @typedef {import('./Route.js').RouteResponse} RouteResponse */
/** @typedef {import('./Route.js').RouteResponseData} RouteResponseData */
/** @typedef {import('./Route.js').RouteResponseObjectData} RouteResponseObjectData */
/** @typedef {import('./Route.js').RouteResponseConfig} RouteResponseConfig */
/** @typedef {import('./Route.js').RouteResponseFunction} RouteResponseFunction */
/** @typedef {import('./Matchers.js').RouteMatcher} RouteMatcher */
/** @typedef {import('./FetchMock.js').FetchMockConfig} FetchMockConfig */
/** @typedef {import('./FetchMock.js')} FetchMock */
/** @typedef {import('./CallHistory.js').CallLog} CallLog */

/** @typedef {'body' |'headers' |'throws' |'status' |'redirectUrl' } ResponseConfigProp */

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/Matchers/body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('body matching', () => {
).toBe(true);
});

it('not match when not starting subset of array', () => {
it('match when subset of array has gaps', () => {
const route = new Route({
body: { ham: [1, 3] },
matchPartialBody: true,
Expand All @@ -225,7 +225,7 @@ describe('body matching', () => {
body: JSON.stringify({ ham: [1, 2, 3] }),
},
}),
).toBe(false);
).toBe(true);
});
});
});
1 change: 0 additions & 1 deletion packages/core/src/node_modules/is-subset/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "module"}
{"type": "module"}
12 changes: 6 additions & 6 deletions packages/core/types/CallHistory.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default CallHistory;
export type RouteConfig = import("./Route").RouteConfig;
export type RouteName = import("./Route").RouteName;
export type NormalizedRequestOptions = import("./RequestUtils").NormalizedRequestOptions;
export type RouteMatcher = import("./Matchers").RouteMatcher;
export type FetchMockConfig = import("./FetchMock").FetchMockConfig;
export type RouteConfig = import("./Route.js").RouteConfig;
export type RouteName = import("./Route.js").RouteName;
export type NormalizedRequestOptions = import("./RequestUtils.js").NormalizedRequestOptions;
export type RouteMatcher = import("./Matchers.js").RouteMatcher;
export type FetchMockConfig = import("./FetchMock.js").FetchMockConfig;
export type CallLog = {
arguments: any[];
url: string;
Expand All @@ -26,7 +26,7 @@ export type CallHistoryFilter = RouteName | Matched | Unmatched | boolean | Rout
declare class CallHistory {
constructor(globalConfig: FetchMockConfig, router: Router);
callLogs: CallLog[];
config: import("./FetchMock").FetchMockConfig;
config: import("./FetchMock.js").FetchMockConfig;
router: Router;
recordCall(callLog: CallLog): void;
clear(): void;
Expand Down
14 changes: 7 additions & 7 deletions packages/core/types/FetchMock.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default fetchMock;
export type RouteMatcher = import("./Router").RouteMatcher;
export type RouteName = import("./Route").RouteName;
export type UserRouteConfig = import("./Route").UserRouteConfig;
export type RouteResponse = import("./Router").RouteResponse;
export type MatcherDefinition = import("./Matchers").MatcherDefinition;
export type CallLog = import("./CallHistory").CallLog;
export type RouteResponseFunction = import("./Route").RouteResponseFunction;
export type RouteMatcher = import("./Router.js").RouteMatcher;
export type RouteName = import("./Route.js").RouteName;
export type UserRouteConfig = import("./Route.js").UserRouteConfig;
export type RouteResponse = import("./Router.js").RouteResponse;
export type MatcherDefinition = import("./Matchers.js").MatcherDefinition;
export type CallLog = import("./CallHistory.js").CallLog;
export type RouteResponseFunction = import("./Route.js").RouteResponseFunction;
export type FetchMockGlobalConfig = {
sendAsJson?: boolean;
includeContentLength?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/Matchers.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export function isUrlMatcher(matcher: RouteMatcher | RouteConfig): matcher is RouteMatcherUrl;
export function isFunctionMatcher(matcher: RouteMatcher | RouteConfig): matcher is RouteMatcherFunction;
export const builtInMatchers: MatcherDefinition[];
export type RouteConfig = import("./Route").RouteConfig;
export type CallLog = import("./CallHistory").CallLog;
export type RouteConfig = import("./Route.js").RouteConfig;
export type CallLog = import("./CallHistory.js").CallLog;
export type RouteMatcherUrl = string | RegExp | URL;
export type UrlMatcherGenerator = (arg0: string) => RouteMatcherFunction;
export type RouteMatcherFunction = (arg0: CallLog) => boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/RequestUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export type DerivedRequestOptions = {
};
};
export type NormalizedRequestOptions = RequestInit | (RequestInit & DerivedRequestOptions);
export type CallLog = import("./CallHistory").CallLog;
export type CallLog = import("./CallHistory.js").CallLog;
14 changes: 7 additions & 7 deletions packages/core/types/Route.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export default Route;
export type RouteMatcher = import("./Matchers").RouteMatcher;
export type CallLog = import("./CallHistory").CallLog;
export type RouteMatcherFunction = import("./Matchers").RouteMatcherFunction;
export type RouteMatcherUrl = import("./Matchers").RouteMatcherUrl;
export type MatcherDefinition = import("./Matchers").MatcherDefinition;
export type FetchMockGlobalConfig = import("./FetchMock").FetchMockGlobalConfig;
export type FetchImplementations = import("./FetchMock").FetchImplementations;
export type RouteMatcher = import("./Matchers.js").RouteMatcher;
export type CallLog = import("./CallHistory.js").CallLog;
export type RouteMatcherFunction = import("./Matchers.js").RouteMatcherFunction;
export type RouteMatcherUrl = import("./Matchers.js").RouteMatcherUrl;
export type MatcherDefinition = import("./Matchers.js").MatcherDefinition;
export type FetchMockGlobalConfig = import("./FetchMock.js").FetchMockGlobalConfig;
export type FetchImplementations = import("./FetchMock.js").FetchImplementations;
export type UserRouteConfig = {
name?: RouteName;
method?: string;
Expand Down
24 changes: 12 additions & 12 deletions packages/core/types/Router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class Router {
fallbackRoute?: Route;
});
routes: Route[];
config: import("./FetchMock").FetchMockConfig;
config: import("./FetchMock.js").FetchMockConfig;
fallbackRoute: Route;
needsToReadBody(request: Request): boolean;
execute(callLog: CallLog): Promise<Response>;
Expand All @@ -22,16 +22,16 @@ export default class Router {
includeFallback?: boolean;
}): void;
}
export type UserRouteConfig = import("./Route").UserRouteConfig;
export type RouteConfig = import("./Route").RouteConfig;
export type RouteResponse = import("./Route").RouteResponse;
export type RouteResponseData = import("./Route").RouteResponseData;
export type RouteResponseObjectData = import("./Route").RouteResponseObjectData;
export type RouteResponseConfig = import("./Route").RouteResponseConfig;
export type RouteResponseFunction = import("./Route").RouteResponseFunction;
export type RouteMatcher = import("./Matchers").RouteMatcher;
export type FetchMockConfig = import("./FetchMock").FetchMockConfig;
export type FetchMock = typeof import("./FetchMock");
export type CallLog = import("./CallHistory").CallLog;
export type UserRouteConfig = import("./Route.js").UserRouteConfig;
export type RouteConfig = import("./Route.js").RouteConfig;
export type RouteResponse = import("./Route.js").RouteResponse;
export type RouteResponseData = import("./Route.js").RouteResponseData;
export type RouteResponseObjectData = import("./Route.js").RouteResponseObjectData;
export type RouteResponseConfig = import("./Route.js").RouteResponseConfig;
export type RouteResponseFunction = import("./Route.js").RouteResponseFunction;
export type RouteMatcher = import("./Matchers.js").RouteMatcher;
export type FetchMockConfig = import("./FetchMock.js").FetchMockConfig;
export type FetchMock = typeof import("./FetchMock.js");
export type CallLog = import("./CallHistory.js").CallLog;
export type ResponseConfigProp = "body" | "headers" | "throws" | "status" | "redirectUrl";
import Route from './Route.js';

0 comments on commit 9e0bc09

Please sign in to comment.