@schmock/core 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -0
- package/dist/abort.d.ts +11 -1
- package/dist/abort.js +13 -2
- package/dist/adapter.d.ts +19 -0
- package/dist/adapter.js +17 -0
- package/dist/admission.d.ts +21 -0
- package/dist/admission.js +39 -0
- package/dist/binary.d.ts +0 -1
- package/dist/builder.d.ts +16 -32
- package/dist/builder.js +397 -903
- package/dist/constants.d.ts +33 -2
- package/dist/constants.js +73 -1
- package/dist/debug-logger.d.ts +10 -0
- package/dist/debug-logger.js +31 -0
- package/dist/delay.d.ts +12 -0
- package/dist/delay.js +37 -0
- package/dist/errors.d.ts +13 -2
- package/dist/errors.js +21 -2
- package/dist/events.d.ts +17 -0
- package/dist/events.js +58 -0
- package/dist/generations.d.ts +43 -0
- package/dist/generations.js +75 -0
- package/dist/headers.d.ts +27 -0
- package/dist/headers.js +57 -0
- package/dist/helpers.d.ts +9 -10
- package/dist/helpers.js +4 -1
- package/dist/history.d.ts +56 -0
- package/dist/history.js +230 -0
- package/dist/http-helpers.d.ts +110 -5
- package/dist/http-helpers.js +328 -46
- package/dist/index.d.ts +213 -31
- package/dist/index.js +17 -9
- package/dist/interceptor.d.ts +15 -11
- package/dist/interceptor.js +241 -164
- package/dist/node-server.d.ts +27 -0
- package/dist/node-server.js +166 -0
- package/dist/parser.d.ts +0 -1
- package/dist/parser.js +145 -22
- package/dist/plugin-hooks.d.ts +40 -0
- package/dist/plugin-hooks.js +192 -0
- package/dist/plugin-pipeline.d.ts +0 -1
- package/dist/plugin-pipeline.js +25 -4
- package/dist/response-normalizer.d.ts +36 -1
- package/dist/response-normalizer.js +102 -0
- package/dist/response-parser.d.ts +19 -1
- package/dist/response-parser.js +77 -19
- package/dist/route-matcher.d.ts +0 -1
- package/dist/route-table.d.ts +64 -0
- package/dist/route-table.js +220 -0
- package/dist/types.d.ts +27 -1
- package/package.json +8 -3
- package/dist/abort.d.ts.map +0 -1
- package/dist/binary.d.ts.map +0 -1
- package/dist/builder.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/helpers.d.ts.map +0 -1
- package/dist/http-helpers.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interceptor.d.ts.map +0 -1
- package/dist/parser.d.ts.map +0 -1
- package/dist/plugin-pipeline.d.ts.map +0 -1
- package/dist/response-normalizer.d.ts.map +0 -1
- package/dist/response-parser.d.ts.map +0 -1
- package/dist/route-matcher.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -112,6 +112,22 @@ namespace Schmock {
|
|
|
112
112
|
*/
|
|
113
113
|
type RouteKey = `${HttpMethod} /${string}`;
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* What a synchronous plugin hook (`install`, `uninstall`) may return: any
|
|
117
|
+
* value except a thenable, which is ignored. A thenable would mean the hook
|
|
118
|
+
* finishes later, which the synchronous install contract cannot honour.
|
|
119
|
+
*/
|
|
120
|
+
type PluginHookResult =
|
|
121
|
+
| void
|
|
122
|
+
| undefined
|
|
123
|
+
| null
|
|
124
|
+
| string
|
|
125
|
+
| number
|
|
126
|
+
| boolean
|
|
127
|
+
| bigint
|
|
128
|
+
| symbol
|
|
129
|
+
| (object & { then?: never });
|
|
130
|
+
|
|
115
131
|
/**
|
|
116
132
|
* Plugin interface for extending Schmock functionality
|
|
117
133
|
*/
|
|
@@ -125,16 +141,24 @@ namespace Schmock {
|
|
|
125
141
|
* Called once when the plugin is added via .pipe()
|
|
126
142
|
* Route registrations are committed atomically only when this hook returns
|
|
127
143
|
* synchronously. The scoped instance must not be retained or used later.
|
|
128
|
-
*
|
|
144
|
+
*
|
|
145
|
+
* Returning a Promise is unsupported: `pipe()` rejects it at runtime with
|
|
146
|
+
* `PLUGIN_ASYNC_INSTALL_UNSUPPORTED`, and the return type makes an
|
|
147
|
+
* `async install()` a compile error too. Any other return value is
|
|
148
|
+
* accepted and ignored, so an expression-bodied arrow that registers a
|
|
149
|
+
* route (`install: (mock) => mock("GET /health", { ok: true })`, which
|
|
150
|
+
* returns the instance) type-checks as it always has.
|
|
129
151
|
* @param instance - A synchronous, installation-scoped callable instance
|
|
130
152
|
*/
|
|
131
|
-
install?(instance: CallableMockInstance):
|
|
153
|
+
install?(instance: CallableMockInstance): PluginHookResult;
|
|
132
154
|
|
|
133
155
|
/**
|
|
134
156
|
* Called during reset after every request admitted with this plugin settles.
|
|
135
|
-
* Cleanup runs in reverse registration order and must complete synchronously
|
|
157
|
+
* Cleanup runs in reverse registration order and must complete synchronously;
|
|
158
|
+
* as with `install`, an async hook is a compile error and any other return
|
|
159
|
+
* value is ignored.
|
|
136
160
|
*/
|
|
137
|
-
uninstall?(instance: CallableMockInstance):
|
|
161
|
+
uninstall?(instance: CallableMockInstance): PluginHookResult;
|
|
138
162
|
|
|
139
163
|
/**
|
|
140
164
|
* Inspect or transform a request before its route generator executes.
|
|
@@ -651,8 +675,15 @@ namespace Schmock {
|
|
|
651
675
|
response: AdapterResponse,
|
|
652
676
|
request: AdapterRequest,
|
|
653
677
|
) => AdapterResponse | void | Promise<AdapterResponse | void>;
|
|
654
|
-
/**
|
|
655
|
-
|
|
678
|
+
/**
|
|
679
|
+
* Format errors into custom response bodies.
|
|
680
|
+
*
|
|
681
|
+
* `request` is passed the way the Express and Angular adapters pass
|
|
682
|
+
* theirs: the request as routed, after `beforeRequest` once that hook has
|
|
683
|
+
* returned. When the request body itself could not be read, it is the
|
|
684
|
+
* incoming request without a body.
|
|
685
|
+
*/
|
|
686
|
+
errorFormatter?: (error: Error, request: AdapterRequest) => unknown;
|
|
656
687
|
}
|
|
657
688
|
|
|
658
689
|
interface InterceptHandle {
|
|
@@ -669,6 +700,86 @@ namespace Schmock {
|
|
|
669
700
|
readonly active: boolean;
|
|
670
701
|
}
|
|
671
702
|
|
|
703
|
+
// ===== Transport Primitives =====
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* A route result taken apart the way core's response parser reads it.
|
|
707
|
+
* Returned by `getResponseParts()`.
|
|
708
|
+
*
|
|
709
|
+
* - `"object"`: a `{ status, body, headers? }` envelope. `headers`, when
|
|
710
|
+
* present, must be a string record, or the value is not an envelope.
|
|
711
|
+
* - `"tuple"`: `[status, body]` or `[status, body, headers]`.
|
|
712
|
+
* - `"plain"`: anything else, delivered whole as the body.
|
|
713
|
+
*/
|
|
714
|
+
interface ResponseParts {
|
|
715
|
+
/** The status core answers with: a plain `null`/`undefined` body is 204. */
|
|
716
|
+
status: number;
|
|
717
|
+
/** The body element as carried. Core sends no body for `null`/`undefined`. */
|
|
718
|
+
body: unknown;
|
|
719
|
+
/**
|
|
720
|
+
* A copy of the carried headers. A tuple whose third element is not a
|
|
721
|
+
* string record yields `{}` here, and core rejects it as INVALID_RESPONSE.
|
|
722
|
+
*/
|
|
723
|
+
headers: Record<string, string>;
|
|
724
|
+
kind: "plain" | "tuple" | "object";
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* A parsed `baseUrl` or namespace. Returned by `parsePathPrefix()` and read
|
|
729
|
+
* by `matchPathPrefix()`.
|
|
730
|
+
*/
|
|
731
|
+
interface PathPrefix {
|
|
732
|
+
/** The origin an origin-form prefix names, or `null` for a path prefix. */
|
|
733
|
+
origin: string | null;
|
|
734
|
+
/**
|
|
735
|
+
* The canonical (percent-encoded) path, without a trailing slash; `""`
|
|
736
|
+
* when the prefix is the root and matches every path.
|
|
737
|
+
*/
|
|
738
|
+
path: string;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** Routes one request: the signature of `CallableMockInstance.handle`. */
|
|
742
|
+
type MockRequestHandler = (
|
|
743
|
+
method: HttpMethod,
|
|
744
|
+
path: string,
|
|
745
|
+
options?: RequestOptions,
|
|
746
|
+
) => Promise<Response>;
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* One request admitted against a snapshot of a mock's routes and plugins.
|
|
750
|
+
* `handle` must be called at most once, and `release` exactly once after
|
|
751
|
+
* the request settles, so a `reset()` waits for it before uninstalling.
|
|
752
|
+
* Acquired through `acquireRequestAdmission()` from `@schmock/core/adapter`.
|
|
753
|
+
*/
|
|
754
|
+
interface RequestAdmission {
|
|
755
|
+
handle: MockRequestHandler;
|
|
756
|
+
release(): void;
|
|
757
|
+
/**
|
|
758
|
+
* Whether `handle(method, path)` would reach a route, answered from the
|
|
759
|
+
* same snapshot and by the same resolver `handle` uses: a `false` must
|
|
760
|
+
* never be wrong, or a request a route answers would be passed through.
|
|
761
|
+
* The fetch interceptor asks it, when present, to skip reading the body
|
|
762
|
+
* of a request that will pass through anyway. Admissions from
|
|
763
|
+
* `schmock()` carry it.
|
|
764
|
+
*/
|
|
765
|
+
hasRoute?(method: HttpMethod, path: string): boolean;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/** Input to `buildFormattedErrorResponse()`. */
|
|
769
|
+
interface FormattedErrorOptions {
|
|
770
|
+
/** The `errorFormatter` hook, called exactly once. */
|
|
771
|
+
formatter: (error: Error) => unknown;
|
|
772
|
+
/** The error being formatted. */
|
|
773
|
+
error: Error;
|
|
774
|
+
/**
|
|
775
|
+
* Headers of the response being replaced (e.g. `retry-after`). Kept when
|
|
776
|
+
* they can be sent, minus any content type: a formatted body is JSON.
|
|
777
|
+
*/
|
|
778
|
+
inheritedHeaders?: Record<string, string>;
|
|
779
|
+
/** Request method; a HEAD response carries no body. */
|
|
780
|
+
method: string;
|
|
781
|
+
}
|
|
782
|
+
|
|
672
783
|
// ===== Lifecycle Events =====
|
|
673
784
|
|
|
674
785
|
/**
|
|
@@ -771,7 +882,12 @@ namespace Schmock {
|
|
|
771
882
|
* Context for schema-based data generation
|
|
772
883
|
*/
|
|
773
884
|
interface SchemaGenerationContext {
|
|
774
|
-
|
|
885
|
+
/**
|
|
886
|
+
* The schema to generate from. Typed `Schema` so an inline literal may use
|
|
887
|
+
* the `faker`, `schmockNullable` and `schmockTrueProbability` keywords; a
|
|
888
|
+
* plain `JSONSchema7` is still accepted.
|
|
889
|
+
*/
|
|
890
|
+
schema: Schema;
|
|
775
891
|
count?: number;
|
|
776
892
|
overrides?: Record<string, unknown>;
|
|
777
893
|
params?: Record<string, string>;
|
|
@@ -784,7 +900,12 @@ namespace Schmock {
|
|
|
784
900
|
* Options for the faker plugin
|
|
785
901
|
*/
|
|
786
902
|
interface FakerPluginOptions {
|
|
787
|
-
|
|
903
|
+
/**
|
|
904
|
+
* The schema to generate from. Typed `Schema` so an inline literal may use
|
|
905
|
+
* the `faker`, `schmockNullable` and `schmockTrueProbability` keywords; a
|
|
906
|
+
* plain `JSONSchema7` is still accepted.
|
|
907
|
+
*/
|
|
908
|
+
schema: Schema;
|
|
788
909
|
count?: number;
|
|
789
910
|
overrides?: Record<string, unknown>;
|
|
790
911
|
seed?: number;
|
|
@@ -799,6 +920,10 @@ namespace Schmock {
|
|
|
799
920
|
|
|
800
921
|
/**
|
|
801
922
|
* Configuration options for Express adapter
|
|
923
|
+
*
|
|
924
|
+
* @deprecated Import `ExpressAdapterOptions` from `@schmock/express`, which
|
|
925
|
+
* types `req`/`res` as Express's `Request`/`Response`. This copy types them
|
|
926
|
+
* `unknown` and will be removed in the next major version.
|
|
802
927
|
*/
|
|
803
928
|
interface ExpressAdapterOptions {
|
|
804
929
|
errorFormatter?: (error: Error, req: unknown) => unknown;
|
|
@@ -825,6 +950,10 @@ namespace Schmock {
|
|
|
825
950
|
|
|
826
951
|
/**
|
|
827
952
|
* Configuration options for Angular adapter
|
|
953
|
+
*
|
|
954
|
+
* @deprecated Import `AngularAdapterOptions` from `@schmock/angular`, which
|
|
955
|
+
* types `request` as Angular's `HttpRequest`. This copy types it `unknown`
|
|
956
|
+
* and will be removed in the next major version.
|
|
828
957
|
*/
|
|
829
958
|
interface AngularAdapterOptions {
|
|
830
959
|
baseUrl?: string;
|
|
@@ -832,6 +961,26 @@ namespace Schmock {
|
|
|
832
961
|
errorFormatter?: (error: Error, request: unknown) => unknown;
|
|
833
962
|
transformRequest?: (request: unknown) => AdapterRequestOverride;
|
|
834
963
|
transformResponse?: (response: Response, request: unknown) => Response;
|
|
964
|
+
/**
|
|
965
|
+
* `transformRequest` under the fetch interceptor's name; it may be async,
|
|
966
|
+
* and returning nothing leaves the request unchanged. When both are set,
|
|
967
|
+
* `transformRequest` is used.
|
|
968
|
+
*/
|
|
969
|
+
beforeRequest?: (
|
|
970
|
+
request: unknown,
|
|
971
|
+
) =>
|
|
972
|
+
| AdapterRequestOverride
|
|
973
|
+
| void
|
|
974
|
+
| Promise<AdapterRequestOverride | undefined>;
|
|
975
|
+
/**
|
|
976
|
+
* `transformResponse` under the fetch interceptor's name; it may be async,
|
|
977
|
+
* and returning nothing keeps the response. When both are set,
|
|
978
|
+
* `transformResponse` is used.
|
|
979
|
+
*/
|
|
980
|
+
beforeResponse?: (
|
|
981
|
+
response: Response,
|
|
982
|
+
request: unknown,
|
|
983
|
+
) => Response | void | Promise<Response | undefined>;
|
|
835
984
|
}
|
|
836
985
|
|
|
837
986
|
// ===== OpenAPI Plugin Options =====
|
|
@@ -863,17 +1012,19 @@ namespace Schmock {
|
|
|
863
1012
|
allowHttp?: boolean;
|
|
864
1013
|
/**
|
|
865
1014
|
* Hostnames an `http(s)` `$ref` may target. Empty or omitted means any
|
|
866
|
-
* host, still minus loopback, link-local and
|
|
1015
|
+
* host, still minus loopback, link-local, private and reserved ranges,
|
|
1016
|
+
* checked against every address a host resolves to, so an allow-listed
|
|
1017
|
+
* name that resolves to one is refused too.
|
|
867
1018
|
*/
|
|
868
1019
|
allowedHosts?: string[];
|
|
869
1020
|
/** Per-request timeout for http `$ref`s, in ms. Default 5000. */
|
|
870
1021
|
timeoutMs?: number;
|
|
871
1022
|
/**
|
|
872
|
-
*
|
|
1023
|
+
* Maximum redirect hops to follow for an http `$ref`. Default 0.
|
|
873
1024
|
*
|
|
874
|
-
*
|
|
875
|
-
* `0` refuses
|
|
876
|
-
*
|
|
1025
|
+
* Every hop is checked against `allowHttp` and `allowedHosts` before it
|
|
1026
|
+
* is followed. `0` refuses the first redirect; `n` follows up to `n` hops
|
|
1027
|
+
* and refuses the next one.
|
|
877
1028
|
*/
|
|
878
1029
|
redirects?: number;
|
|
879
1030
|
/** Maximum size of a single http `$ref` document, in bytes. Default 1 MB. */
|
|
@@ -915,18 +1066,27 @@ namespace Schmock {
|
|
|
915
1066
|
/** Replace response schemas for specific routes. Key format: "METHOD /path" or "METHOD /path STATUS" */
|
|
916
1067
|
schemas?: Record<string, import("json-schema").JSONSchema7>;
|
|
917
1068
|
/** Called before generating a response body. Return a schema to replace the original, or void to keep it. */
|
|
918
|
-
onSchema?:
|
|
919
|
-
schema: import("json-schema").JSONSchema7,
|
|
920
|
-
context: {
|
|
921
|
-
method: string;
|
|
922
|
-
path: string;
|
|
923
|
-
params: Record<string, string>;
|
|
924
|
-
query: Record<string, string>;
|
|
925
|
-
headers: Record<string, string>;
|
|
926
|
-
},
|
|
927
|
-
) => import("json-schema").JSONSchema7 | undefined;
|
|
1069
|
+
onSchema?: OnSchemaCallback;
|
|
928
1070
|
}
|
|
929
1071
|
|
|
1072
|
+
/** The request an {@link OnSchemaCallback} is generating a response for. */
|
|
1073
|
+
interface OnSchemaContext {
|
|
1074
|
+
method: string;
|
|
1075
|
+
path: string;
|
|
1076
|
+
params: Record<string, string>;
|
|
1077
|
+
query: Record<string, string>;
|
|
1078
|
+
headers: Record<string, string>;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* `OpenApiOptions.onSchema`: called before a response body is generated.
|
|
1083
|
+
* Return a schema to replace the original, or `undefined` to keep it.
|
|
1084
|
+
*/
|
|
1085
|
+
type OnSchemaCallback = (
|
|
1086
|
+
schema: import("json-schema").JSONSchema7,
|
|
1087
|
+
context: OnSchemaContext,
|
|
1088
|
+
) => import("json-schema").JSONSchema7 | undefined;
|
|
1089
|
+
|
|
930
1090
|
/**
|
|
931
1091
|
* Seed data source: inline array, file path, or auto-generate count
|
|
932
1092
|
*/
|
|
@@ -963,6 +1123,10 @@ namespace Schmock {
|
|
|
963
1123
|
* How many requests the mock retains for `GET /schmock-admin/history`
|
|
964
1124
|
* (`--admin-history-limit`, default 500). Ignored — history is disabled
|
|
965
1125
|
* entirely — when `admin` is off.
|
|
1126
|
+
*
|
|
1127
|
+
* It becomes the mock's {@link GlobalConfig.maxHistorySize} and applies
|
|
1128
|
+
* only while the admin API is on; it defaults to 500 where a core mock's
|
|
1129
|
+
* history is unbounded.
|
|
966
1130
|
*/
|
|
967
1131
|
adminHistoryLimit?: number;
|
|
968
1132
|
/** Validate the spec against the OpenAPI schema at startup (`--strict`). */
|
|
@@ -1020,6 +1184,7 @@ namespace Schmock {
|
|
|
1020
1184
|
}
|
|
1021
1185
|
}
|
|
1022
1186
|
// >>> schmock ambient namespace <<<
|
|
1187
|
+
import { createFetchInterceptor as createAdapterFetchInterceptor } from "./interceptor.js";
|
|
1023
1188
|
/**
|
|
1024
1189
|
* Create a new Schmock mock instance with callable API.
|
|
1025
1190
|
*
|
|
@@ -1044,13 +1209,30 @@ namespace Schmock {
|
|
|
1044
1209
|
* @returns A callable mock instance
|
|
1045
1210
|
*/
|
|
1046
1211
|
export declare function schmock(config?: Schmock.GlobalConfig): Schmock.CallableMockInstance;
|
|
1212
|
+
/**
|
|
1213
|
+
* @deprecated Use `mock.intercept()`, which also tracks the lease and admits
|
|
1214
|
+
* each request against the mock's routes. Adapter authors who need the raw
|
|
1215
|
+
* interceptor import `createFetchInterceptor` from `@schmock/core/adapter`.
|
|
1216
|
+
* This root export will be removed in the next major version.
|
|
1217
|
+
*/
|
|
1218
|
+
export declare const createFetchInterceptor: typeof createAdapterFetchInterceptor;
|
|
1047
1219
|
export { isBinaryBody } from "./binary.js";
|
|
1048
|
-
export { getResponseException, HTTP_METHODS, isHttpMethod, isRouteNotFound, isStatusTuple, ROUTE_NOT_FOUND_CODE, toHttpMethod, toRouteKey, } from "./constants.js";
|
|
1049
|
-
export { InvalidResponseError, PluginError, ResourceLimitError, RouteDefinitionError, RouteNotFoundError, RouteParseError, SchemaGenerationError, SchemaValidationError, SchmockError, } from "./errors.js";
|
|
1220
|
+
export { getResponseException, HTTP_METHODS, isHttpMethod, isRouteNotFound, isStatusTuple, matchPathPrefix, parsePathPrefix, ROUTE_NOT_FOUND_CODE, toHttpMethod, toRouteKey, } from "./constants.js";
|
|
1221
|
+
export { InvalidHttpMethodError, InvalidResponseError, PluginError, ResourceLimitError, RouteDefinitionError, RouteNotFoundError, RouteParseError, SchemaGenerationError, SchemaValidationError, SchmockError, } from "./errors.js";
|
|
1222
|
+
export { getHeader, redactHeaders, SENSITIVE_HEADER_NAMES, } from "./headers.js";
|
|
1050
1223
|
export { badRequest, created, forbidden, noContent, notFound, paginate, serverError, unauthorized, } from "./helpers.js";
|
|
1051
|
-
export type { HttpIngressErrorCode } from "./http-helpers.js";
|
|
1052
|
-
export { collectBody, HttpIngressError, parseNodeHeaders, parseNodeQuery, writeRejectedSchmockResponse, writeSchmockResponse, } from "./http-helpers.js";
|
|
1053
|
-
export {
|
|
1054
|
-
export {
|
|
1055
|
-
export type { AdapterRequest, AdapterRequestOverride, AdapterResponse,
|
|
1056
|
-
|
|
1224
|
+
export type { HttpErrorReply, HttpIngressErrorCode, NodeRequestLike, NodeResponseLike, ServeNodeRequestOptions, ServeNodeResponseContext, } from "./http-helpers.js";
|
|
1225
|
+
export { collectBody, HttpIngressError, parseNodeHeaders, parseNodeQuery, serveNodeRequest, writeRejectedSchmockResponse, writeSchmockResponse, } from "./http-helpers.js";
|
|
1226
|
+
export { buildFormattedErrorResponse, normalizeResponse, serializeResponseBody, withDefaultContentType, } from "./response-normalizer.js";
|
|
1227
|
+
export { getResponseParts, replaceResponseBody, } from "./response-parser.js";
|
|
1228
|
+
export type { AdapterRequest, AdapterRequestOverride, AdapterResponse,
|
|
1229
|
+
/**
|
|
1230
|
+
* @deprecated Import `AngularAdapterOptions` from `@schmock/angular`; this
|
|
1231
|
+
* copy will be removed in the next major version.
|
|
1232
|
+
*/
|
|
1233
|
+
AngularAdapterOptions, CallableMockInstance, CrudOperationMeta,
|
|
1234
|
+
/**
|
|
1235
|
+
* @deprecated Import `ExpressAdapterOptions` from `@schmock/express`; this
|
|
1236
|
+
* copy will be removed in the next major version.
|
|
1237
|
+
*/
|
|
1238
|
+
ExpressAdapterOptions, FakerPluginOptions, FormattedErrorOptions, Generator, GeneratorFunction, GlobalConfig, HttpMethod, InterceptHandle, InterceptOptions, OnSchemaCallback, OnSchemaContext, OpenApiCallbackOptions, OpenApiCallbackRequest, OpenApiOptions, OpenApiRefPolicy, PaginatedResponse, PaginateOptions, PathPrefix, Plugin, PluginContext, PluginHookResult, PluginResult, RequestContext, RequestEndEvent, RequestMatchEvent, RequestNotFoundEvent, RequestOptions, RequestRecord, RequestStartEvent, ResourceOverride, Response, ResponseBody, ResponseHeaderDef, ResponseParts, ResponseResult, RouteConfig, RouteInfo, RouteKey, Schema, SchemaDefinition, SchemaGenerationContext, SchmockEvent, SchmockEventMap, SeedConfig, SeedSource, ServerInfo, StaticData, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { REQUEST_ADMISSION_KEY } from "./admission.js";
|
|
1
2
|
import { CallableMockInstance } from "./builder.js";
|
|
2
|
-
|
|
3
|
+
import { createFetchInterceptor as createAdapterFetchInterceptor } from "./interceptor.js";
|
|
3
4
|
/**
|
|
4
5
|
* Create a new Schmock mock instance with callable API.
|
|
5
6
|
*
|
|
@@ -57,22 +58,29 @@ export function schmock(config) {
|
|
|
57
58
|
close: instance.close.bind(instance),
|
|
58
59
|
intercept: (options) => instance.intercept(options),
|
|
59
60
|
});
|
|
60
|
-
Object.defineProperty(callableInstance,
|
|
61
|
+
Object.defineProperty(callableInstance, REQUEST_ADMISSION_KEY, {
|
|
61
62
|
value: () => instance.createRequestAdmission(),
|
|
62
63
|
});
|
|
63
64
|
instance.setCallableRef(callableInstance);
|
|
64
65
|
return callableInstance;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use `mock.intercept()`, which also tracks the lease and admits
|
|
69
|
+
* each request against the mock's routes. Adapter authors who need the raw
|
|
70
|
+
* interceptor import `createFetchInterceptor` from `@schmock/core/adapter`.
|
|
71
|
+
* This root export will be removed in the next major version.
|
|
72
|
+
*/
|
|
73
|
+
export const createFetchInterceptor = createAdapterFetchInterceptor;
|
|
66
74
|
export { isBinaryBody } from "./binary.js";
|
|
67
75
|
// Re-export constants and utilities
|
|
68
|
-
export { getResponseException, HTTP_METHODS, isHttpMethod, isRouteNotFound, isStatusTuple, ROUTE_NOT_FOUND_CODE, toHttpMethod, toRouteKey, } from "./constants.js";
|
|
76
|
+
export { getResponseException, HTTP_METHODS, isHttpMethod, isRouteNotFound, isStatusTuple, matchPathPrefix, parsePathPrefix, ROUTE_NOT_FOUND_CODE, toHttpMethod, toRouteKey, } from "./constants.js";
|
|
69
77
|
// Re-export errors
|
|
70
|
-
export { InvalidResponseError, PluginError, ResourceLimitError, RouteDefinitionError, RouteNotFoundError, RouteParseError, SchemaGenerationError, SchemaValidationError, SchmockError, } from "./errors.js";
|
|
78
|
+
export { InvalidHttpMethodError, InvalidResponseError, PluginError, ResourceLimitError, RouteDefinitionError, RouteNotFoundError, RouteParseError, SchemaGenerationError, SchemaValidationError, SchmockError, } from "./errors.js";
|
|
79
|
+
// Re-export header helpers
|
|
80
|
+
export { getHeader, redactHeaders, SENSITIVE_HEADER_NAMES, } from "./headers.js";
|
|
71
81
|
// Re-export response helpers
|
|
72
82
|
export { badRequest, created, forbidden, noContent, notFound, paginate, serverError, unauthorized, } from "./helpers.js";
|
|
73
83
|
// Re-export HTTP server helpers
|
|
74
|
-
export { collectBody, HttpIngressError, parseNodeHeaders, parseNodeQuery, writeRejectedSchmockResponse, writeSchmockResponse, } from "./http-helpers.js";
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export { createFetchInterceptor } from "./interceptor.js";
|
|
78
|
-
export { normalizeResponse, serializeResponseBody, } from "./response-normalizer.js";
|
|
84
|
+
export { collectBody, HttpIngressError, parseNodeHeaders, parseNodeQuery, serveNodeRequest, writeRejectedSchmockResponse, writeSchmockResponse, } from "./http-helpers.js";
|
|
85
|
+
export { buildFormattedErrorResponse, normalizeResponse, serializeResponseBody, withDefaultContentType, } from "./response-normalizer.js";
|
|
86
|
+
export { getResponseParts, replaceResponseBody, } from "./response-parser.js";
|
package/dist/interceptor.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Marks an admission whose `handle()` already returns responses normalized
|
|
3
|
+
* for the request method (hop-by-hop headers dropped, a HEAD body stripped):
|
|
4
|
+
* only the admissions a `schmock()` instance of this copy creates. The
|
|
5
|
+
* interceptor re-normalizes the responses of any other admission, such as a
|
|
6
|
+
* hand-written one passed to `createFetchInterceptor`. Deliberately
|
|
7
|
+
* unregistered: an admission from a second copy of `@schmock/core` is simply
|
|
8
|
+
* normalized again.
|
|
9
|
+
*/
|
|
10
|
+
export declare const NORMALIZED_ADMISSION_KEY: unique symbol;
|
|
6
11
|
/**
|
|
7
12
|
* Create a fetch interceptor that routes requests through mock.handle().
|
|
8
13
|
*
|
|
9
|
-
* `owner` identifies the mock behind the lease. Leases sharing an owner
|
|
10
|
-
*
|
|
11
|
-
*
|
|
14
|
+
* `owner` identifies the mock behind the lease. Leases sharing an owner ask it
|
|
15
|
+
* each distinct effective request (method and path after the lease's own
|
|
16
|
+
* beforeRequest) at most once, so a mock held by several leases runs its
|
|
17
|
+
* handler — and emits its lifecycle events — once per request it is asked.
|
|
12
18
|
*/
|
|
13
|
-
export declare function createFetchInterceptor(handle:
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=interceptor.d.ts.map
|
|
19
|
+
export declare function createFetchInterceptor(handle: Schmock.MockRequestHandler, options?: Schmock.InterceptOptions, admitRequest?: () => Schmock.RequestAdmission, owner?: symbol): Schmock.InterceptHandle;
|