@schmock/core 2.3.0 → 2.4.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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -0
  3. package/dist/abort.d.ts +3 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/abort.js +30 -0
  6. package/dist/builder.d.ts +31 -10
  7. package/dist/builder.d.ts.map +1 -1
  8. package/dist/builder.js +760 -190
  9. package/dist/constants.d.ts +38 -0
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/constants.js +123 -2
  12. package/dist/errors.d.ts +14 -3
  13. package/dist/errors.d.ts.map +1 -1
  14. package/dist/errors.js +41 -6
  15. package/dist/helpers.d.ts +9 -0
  16. package/dist/helpers.d.ts.map +1 -1
  17. package/dist/helpers.js +18 -2
  18. package/dist/http-helpers.d.ts +39 -4
  19. package/dist/http-helpers.d.ts.map +1 -1
  20. package/dist/http-helpers.js +147 -49
  21. package/dist/index.d.ts +292 -34
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8 -3
  24. package/dist/interceptor.d.ts +11 -1
  25. package/dist/interceptor.d.ts.map +1 -1
  26. package/dist/interceptor.js +316 -169
  27. package/dist/parser.d.ts.map +1 -1
  28. package/dist/parser.js +12 -3
  29. package/dist/plugin-pipeline.d.ts +3 -3
  30. package/dist/plugin-pipeline.d.ts.map +1 -1
  31. package/dist/plugin-pipeline.js +29 -14
  32. package/dist/response-normalizer.d.ts +16 -0
  33. package/dist/response-normalizer.d.ts.map +1 -0
  34. package/dist/response-normalizer.js +316 -0
  35. package/dist/response-parser.d.ts.map +1 -1
  36. package/dist/response-parser.js +39 -2
  37. package/dist/route-matcher.d.ts +3 -0
  38. package/dist/route-matcher.d.ts.map +1 -1
  39. package/dist/route-matcher.js +12 -6
  40. package/dist/types.d.ts +7 -2
  41. package/dist/types.d.ts.map +1 -1
  42. package/package.json +18 -6
  43. package/src/audit-core-builder.test.ts +0 -218
  44. package/src/audit-response-guard.test.ts +0 -38
  45. package/src/binary.test.ts +0 -126
  46. package/src/binary.ts +0 -11
  47. package/src/builder.test.ts +0 -289
  48. package/src/builder.ts +0 -748
  49. package/src/constants.test.ts +0 -99
  50. package/src/constants.ts +0 -73
  51. package/src/debug.test.ts +0 -241
  52. package/src/delay.test.ts +0 -319
  53. package/src/dist-shape.test.ts +0 -35
  54. package/src/errors.test.ts +0 -223
  55. package/src/errors.ts +0 -130
  56. package/src/factory.test.ts +0 -133
  57. package/src/helpers.test.ts +0 -147
  58. package/src/helpers.ts +0 -58
  59. package/src/http-helpers.test.ts +0 -39
  60. package/src/http-helpers.ts +0 -149
  61. package/src/index.ts +0 -152
  62. package/src/interceptor.test.ts +0 -488
  63. package/src/interceptor.ts +0 -407
  64. package/src/namespace.test.ts +0 -274
  65. package/src/parser.property.test.ts +0 -630
  66. package/src/parser.test.ts +0 -148
  67. package/src/parser.ts +0 -64
  68. package/src/plugin-pipeline.ts +0 -208
  69. package/src/plugin-system.test.ts +0 -697
  70. package/src/response-parser.ts +0 -114
  71. package/src/response-parsing.test.ts +0 -333
  72. package/src/route-matcher.ts +0 -69
  73. package/src/route-matching.test.ts +0 -394
  74. package/src/server.test.ts +0 -234
  75. package/src/smart-defaults.test.ts +0 -361
  76. package/src/steps/async-support.steps.ts +0 -421
  77. package/src/steps/audit-core-builder.steps.ts +0 -188
  78. package/src/steps/audit-onerror-tuple.steps.ts +0 -83
  79. package/src/steps/basic-usage.steps.ts +0 -245
  80. package/src/steps/developer-experience.steps.ts +0 -204
  81. package/src/steps/error-handling.steps.ts +0 -555
  82. package/src/steps/fetch-interceptor.steps.ts +0 -457
  83. package/src/steps/fluent-api.steps.ts +0 -255
  84. package/src/steps/http-methods.steps.ts +0 -342
  85. package/src/steps/lifecycle-events.steps.ts +0 -149
  86. package/src/steps/performance-reliability.steps.ts +0 -90
  87. package/src/steps/plugin-integration.steps.ts +0 -334
  88. package/src/steps/request-history.steps.ts +0 -458
  89. package/src/steps/response-delay.steps.ts +0 -88
  90. package/src/steps/route-key-format.steps.ts +0 -99
  91. package/src/steps/standalone-server.steps.ts +0 -227
  92. package/src/steps/state-concurrency.steps.ts +0 -167
  93. package/src/types.ts +0 -36
@@ -1,133 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { schmock } from "./index";
3
-
4
- describe("schmock factory function", () => {
5
- describe("factory behavior", () => {
6
- it("creates callable mock instance with no config", () => {
7
- const mock = schmock();
8
-
9
- expect(typeof mock).toBe("function");
10
- expect(typeof mock.handle).toBe("function");
11
- expect(typeof mock.pipe).toBe("function");
12
- });
13
-
14
- it("creates callable mock instance with config", () => {
15
- const config = { debug: true, namespace: "/api" };
16
- const mock = schmock(config);
17
-
18
- expect(typeof mock).toBe("function");
19
- expect(typeof mock.handle).toBe("function");
20
- expect(typeof mock.pipe).toBe("function");
21
- });
22
-
23
- it("supports method chaining from factory call", () => {
24
- const mock = schmock();
25
- const result = mock("GET /test", "response");
26
-
27
- expect(result).toBe(mock); // Should return same instance for chaining
28
- });
29
-
30
- it("supports plugin chaining", () => {
31
- const mock = schmock();
32
- const plugin = {
33
- name: "test",
34
- process: (ctx: any, res: any) => ({ context: ctx, response: res }),
35
- };
36
- const result = mock.pipe(plugin);
37
-
38
- expect(result).toBe(mock); // Should return same instance for chaining
39
- });
40
- });
41
-
42
- describe("callable instance behavior", () => {
43
- it("defines routes when called as function", async () => {
44
- const mock = schmock();
45
- mock("GET /test", "hello");
46
-
47
- const response = await mock.handle("GET", "/test");
48
- expect(response.body).toBe("hello");
49
- });
50
-
51
- it("allows method chaining after route definition", async () => {
52
- const mock = schmock();
53
- const plugin = {
54
- name: "test",
55
- process: (ctx: any, res: any) => ({ context: ctx, response: res }),
56
- };
57
-
58
- mock("GET /test", "hello").pipe(plugin);
59
-
60
- const response = await mock.handle("GET", "/test");
61
- expect(response.body).toBe("hello");
62
- });
63
-
64
- it("passes config to route definition", async () => {
65
- const mock = schmock();
66
- mock("GET /test", { data: "test" }, { contentType: "text/plain" });
67
-
68
- const response = await mock.handle("GET", "/test");
69
- expect(response.headers["content-type"]).toBe("text/plain");
70
- expect(response.body).toBe('{"data":"test"}'); // Stringified because contentType is text/plain
71
- });
72
- });
73
-
74
- describe("binding and method preservation", () => {
75
- it("preserves handle method binding", async () => {
76
- const mock = schmock();
77
- mock("GET /test", "response");
78
-
79
- const handleMethod = mock.handle;
80
- const response = await handleMethod("GET", "/test");
81
-
82
- expect(response.body).toBe("response");
83
- });
84
-
85
- it("allows destructuring of methods", async () => {
86
- const mock = schmock();
87
- mock("GET /test", "response");
88
-
89
- const { handle } = mock;
90
- const response = await handle("GET", "/test");
91
-
92
- expect(response.body).toBe("response");
93
- });
94
-
95
- it("pipes maintain chain references", () => {
96
- const mock = schmock();
97
- const plugin1 = {
98
- name: "plugin1",
99
- process: (ctx: any, res: any) => ({ context: ctx, response: res }),
100
- };
101
- const plugin2 = {
102
- name: "plugin2",
103
- process: (ctx: any, res: any) => ({ context: ctx, response: res }),
104
- };
105
-
106
- const chain = mock.pipe(plugin1).pipe(plugin2);
107
-
108
- expect(chain).toBe(mock);
109
- });
110
- });
111
-
112
- describe("type compatibility", () => {
113
- it("works with TypeScript function signature", () => {
114
- // Test that the factory function matches expected TypeScript types
115
- const mock = schmock({ debug: false });
116
- mock("GET /users", () => [{ id: 1 }], {
117
- contentType: "application/json",
118
- });
119
-
120
- expect(typeof mock).toBe("function");
121
- });
122
-
123
- it("handles optional config parameter", () => {
124
- const mock1 = schmock();
125
- const mock2 = schmock({});
126
- const mock3 = schmock({ debug: true });
127
-
128
- expect(typeof mock1).toBe("function");
129
- expect(typeof mock2).toBe("function");
130
- expect(typeof mock3).toBe("function");
131
- });
132
- });
133
- });
@@ -1,147 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- badRequest,
4
- created,
5
- forbidden,
6
- noContent,
7
- notFound,
8
- paginate,
9
- serverError,
10
- unauthorized,
11
- } from "./helpers.js";
12
-
13
- describe("notFound", () => {
14
- it("returns 404 with default message", () => {
15
- expect(notFound()).toEqual([404, { message: "Not Found" }]);
16
- });
17
- it("returns 404 with custom string message", () => {
18
- expect(notFound("User not found")).toEqual([
19
- 404,
20
- { message: "User not found" },
21
- ]);
22
- });
23
- it("returns 404 with custom object", () => {
24
- expect(notFound({ code: "NOT_FOUND", detail: "gone" })).toEqual([
25
- 404,
26
- { code: "NOT_FOUND", detail: "gone" },
27
- ]);
28
- });
29
- });
30
-
31
- describe("badRequest", () => {
32
- it("returns 400 with default message", () => {
33
- expect(badRequest()).toEqual([400, { message: "Bad Request" }]);
34
- });
35
- it("returns 400 with custom string", () => {
36
- expect(badRequest("Invalid email")).toEqual([
37
- 400,
38
- { message: "Invalid email" },
39
- ]);
40
- });
41
- });
42
-
43
- describe("unauthorized", () => {
44
- it("returns 401 with default message", () => {
45
- expect(unauthorized()).toEqual([401, { message: "Unauthorized" }]);
46
- });
47
- });
48
-
49
- describe("forbidden", () => {
50
- it("returns 403 with default message", () => {
51
- expect(forbidden()).toEqual([403, { message: "Forbidden" }]);
52
- });
53
- });
54
-
55
- describe("serverError", () => {
56
- it("returns 500 with default message", () => {
57
- expect(serverError()).toEqual([500, { message: "Internal Server Error" }]);
58
- });
59
- });
60
-
61
- describe("created", () => {
62
- it("returns 201 with body", () => {
63
- expect(created({ id: 1, name: "John" })).toEqual([
64
- 201,
65
- { id: 1, name: "John" },
66
- ]);
67
- });
68
- });
69
-
70
- describe("noContent", () => {
71
- it("returns 204 with null body", () => {
72
- expect(noContent()).toEqual([204, null]);
73
- });
74
- });
75
-
76
- describe("paginate", () => {
77
- const items = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }];
78
-
79
- it("returns first page with default pageSize", () => {
80
- const result = paginate(items);
81
- expect(result).toEqual({
82
- data: items,
83
- page: 1,
84
- pageSize: 10,
85
- total: 5,
86
- totalPages: 1,
87
- });
88
- });
89
-
90
- it("paginates correctly with custom options", () => {
91
- const result = paginate(items, { page: 2, pageSize: 2 });
92
- expect(result).toEqual({
93
- data: [{ id: 3 }, { id: 4 }],
94
- page: 2,
95
- pageSize: 2,
96
- total: 5,
97
- totalPages: 3,
98
- });
99
- });
100
-
101
- it("returns empty data for page beyond range", () => {
102
- const result = paginate(items, { page: 10, pageSize: 2 });
103
- expect(result.data).toEqual([]);
104
- expect(result.total).toBe(5);
105
- });
106
-
107
- it("page=0 falls back to page 1 (falsy default)", () => {
108
- const result = paginate(items, { page: 0, pageSize: 2 });
109
- // page=0 is falsy, so options.page || 1 => 1
110
- expect(result.page).toBe(1);
111
- expect(result.data).toEqual([{ id: 1 }, { id: 2 }]);
112
- });
113
-
114
- it("pageSize=0 falls back to default 10 (falsy default)", () => {
115
- const result = paginate(items, { pageSize: 0 });
116
- // pageSize=0 is falsy, so options.pageSize || 10 => 10
117
- expect(result.pageSize).toBe(10);
118
- expect(result.data).toEqual(items);
119
- });
120
-
121
- it("handles empty array", () => {
122
- const result = paginate([], { page: 1, pageSize: 5 });
123
- expect(result).toEqual({
124
- data: [],
125
- page: 1,
126
- pageSize: 5,
127
- total: 0,
128
- totalPages: 0,
129
- });
130
- });
131
-
132
- it("negative page produces empty data (start index < 0)", () => {
133
- const result = paginate(items, { page: -1, pageSize: 2 });
134
- // (page - 1) * pageSize = (-1 - 1) * 2 = -4
135
- // items.slice(-4, -2) => items from index 1 to 3
136
- expect(result.page).toBe(-1);
137
- expect(result.pageSize).toBe(2);
138
- expect(result.total).toBe(5);
139
- });
140
-
141
- it("negative pageSize returns empty data", () => {
142
- const result = paginate(items, { page: 1, pageSize: -5 });
143
- // start = 0, end = 0 + (-5) = -5 => items.slice(0, -5) => []
144
- expect(result.data).toEqual([]);
145
- expect(result.pageSize).toBe(-5);
146
- });
147
- });
package/src/helpers.ts DELETED
@@ -1,58 +0,0 @@
1
- /// <reference path="../schmock.d.ts" />
2
-
3
- export function notFound(
4
- message: string | object = "Not Found",
5
- ): [number, object] {
6
- const body = typeof message === "string" ? { message } : message;
7
- return [404, body];
8
- }
9
-
10
- export function badRequest(
11
- message: string | object = "Bad Request",
12
- ): [number, object] {
13
- const body = typeof message === "string" ? { message } : message;
14
- return [400, body];
15
- }
16
-
17
- export function unauthorized(
18
- message: string | object = "Unauthorized",
19
- ): [number, object] {
20
- const body = typeof message === "string" ? { message } : message;
21
- return [401, body];
22
- }
23
-
24
- export function forbidden(
25
- message: string | object = "Forbidden",
26
- ): [number, object] {
27
- const body = typeof message === "string" ? { message } : message;
28
- return [403, body];
29
- }
30
-
31
- export function serverError(
32
- message: string | object = "Internal Server Error",
33
- ): [number, object] {
34
- const body = typeof message === "string" ? { message } : message;
35
- return [500, body];
36
- }
37
-
38
- export function created(body: object): [number, object] {
39
- return [201, body];
40
- }
41
-
42
- export function noContent(): [number, null] {
43
- return [204, null];
44
- }
45
-
46
- export function paginate<T>(
47
- items: T[],
48
- options: Schmock.PaginateOptions = {},
49
- ): Schmock.PaginatedResponse<T> {
50
- const page = options.page || 1;
51
- const pageSize = options.pageSize || 10;
52
- const total = items.length;
53
- const totalPages = Math.ceil(total / pageSize);
54
- const start = (page - 1) * pageSize;
55
- const end = start + pageSize;
56
- const data = items.slice(start, end);
57
- return { data, page, pageSize, total, totalPages };
58
- }
@@ -1,39 +0,0 @@
1
- import { PassThrough } from "node:stream";
2
- import { describe, expect, it } from "vitest";
3
- import { collectBody } from "./http-helpers.js";
4
-
5
- function bodyStream(body: Buffer): PassThrough {
6
- const stream = new PassThrough();
7
- stream.end(body);
8
- return stream;
9
- }
10
-
11
- describe("collectBody size limits", () => {
12
- it("accepts a body exactly at the configured limit", async () => {
13
- const body = Buffer.from("12345");
14
- await expect(collectBody(bodyStream(body), {}, body.length)).resolves.toBe(
15
- "12345",
16
- );
17
- });
18
-
19
- it("accepts and parses JSON below the configured limit", async () => {
20
- const body = Buffer.from('{"ok":true}');
21
- await expect(
22
- collectBody(
23
- bodyStream(body),
24
- { "content-type": "application/json" },
25
- body.length + 1,
26
- ),
27
- ).resolves.toEqual({ ok: true });
28
- });
29
-
30
- it("rejects a body above the configured limit with status 413", async () => {
31
- const body = Buffer.from("123456");
32
- await expect(
33
- collectBody(bodyStream(body), {}, body.length - 1),
34
- ).rejects.toMatchObject({
35
- message: "Request body too large",
36
- status: 413,
37
- });
38
- });
39
- });
@@ -1,149 +0,0 @@
1
- import type { ServerResponse } from "node:http";
2
- import { isBinaryBody } from "./binary.js";
3
-
4
- interface RequestWithHeaders {
5
- readonly headers: {
6
- readonly [header: string]: string | string[] | undefined;
7
- };
8
- }
9
-
10
- interface BodyReadable {
11
- on(event: "error", listener: (error: Error) => void): this;
12
- on(event: "data", listener: (chunk: Buffer) => void): this;
13
- on(event: "end", listener: () => void): this;
14
- destroy(error?: Error): this;
15
- }
16
-
17
- /**
18
- * Convert Node.js IncomingMessage headers to a flat Record<string, string>.
19
- * Drops array-valued headers (keeps only string values).
20
- */
21
- export function parseNodeHeaders(
22
- req: RequestWithHeaders,
23
- ): Record<string, string> {
24
- const headers: Record<string, string> = {};
25
- for (const [key, value] of Object.entries(req.headers)) {
26
- if (typeof value === "string") {
27
- headers[key] = value;
28
- }
29
- }
30
- return headers;
31
- }
32
-
33
- /**
34
- * Extract query parameters from a URL as a flat Record<string, string>.
35
- */
36
- export function parseNodeQuery(url: URL): Record<string, string> {
37
- const query: Record<string, string> = {};
38
- url.searchParams.forEach((value, key) => {
39
- query[key] = value;
40
- });
41
- return query;
42
- }
43
-
44
- /** Default body size limit: 10 MB */
45
- const DEFAULT_MAX_BODY_SIZE = 10 * 1024 * 1024;
46
-
47
- /**
48
- * Collect and parse the request body from a Node.js IncomingMessage.
49
- * Returns parsed JSON if content-type includes "json", otherwise the raw string.
50
- * Returns undefined for empty bodies.
51
- * @param req - Node.js IncomingMessage
52
- * @param headers - Parsed request headers
53
- * @param maxBodySize - Maximum body size in bytes (default: 10 MB)
54
- */
55
- export function collectBody(
56
- req: BodyReadable,
57
- headers: Record<string, string>,
58
- maxBodySize = DEFAULT_MAX_BODY_SIZE,
59
- ): Promise<unknown> {
60
- return new Promise((resolve, reject) => {
61
- const chunks: Buffer[] = [];
62
- let totalSize = 0;
63
-
64
- req.on("error", reject);
65
-
66
- req.on("data", (chunk: Buffer) => {
67
- totalSize += chunk.length;
68
- if (totalSize > maxBodySize) {
69
- req.destroy();
70
- reject(
71
- Object.assign(new Error("Request body too large"), { status: 413 }),
72
- );
73
- return;
74
- }
75
- chunks.push(chunk);
76
- });
77
-
78
- req.on("end", () => {
79
- const raw = Buffer.concat(chunks).toString();
80
- if (!raw) {
81
- resolve(undefined);
82
- return;
83
- }
84
- const contentType = headers["content-type"] ?? "";
85
- if (contentType.includes("json")) {
86
- try {
87
- resolve(JSON.parse(raw));
88
- } catch {
89
- resolve(raw);
90
- }
91
- } else {
92
- resolve(raw);
93
- }
94
- });
95
- });
96
- }
97
-
98
- /**
99
- * Write a Schmock Response to a Node.js ServerResponse.
100
- * Serializes non-string bodies as JSON and sets content-type when missing.
101
- */
102
- export function writeSchmockResponse(
103
- res: ServerResponse,
104
- response: Schmock.Response,
105
- extraHeaders?: Record<string, string>,
106
- ): void {
107
- const responseHeaders: Record<string, string> = {
108
- ...response.headers,
109
- ...extraHeaders,
110
- };
111
-
112
- const hasContentType = Object.keys(responseHeaders).some(
113
- (header) => header.toLowerCase() === "content-type",
114
- );
115
-
116
- if (
117
- !hasContentType &&
118
- response.body !== undefined &&
119
- isBinaryBody(response.body)
120
- ) {
121
- responseHeaders["content-type"] = "application/octet-stream";
122
- } else if (
123
- !hasContentType &&
124
- response.body !== undefined &&
125
- typeof response.body !== "string"
126
- ) {
127
- responseHeaders["content-type"] = "application/json";
128
- }
129
-
130
- let responseBody: string | Uint8Array | undefined;
131
- if (response.body === undefined) {
132
- responseBody = undefined;
133
- } else if (typeof response.body === "string") {
134
- responseBody = response.body;
135
- } else if (response.body instanceof ArrayBuffer) {
136
- responseBody = new Uint8Array(response.body);
137
- } else if (ArrayBuffer.isView(response.body)) {
138
- responseBody = new Uint8Array(
139
- response.body.buffer,
140
- response.body.byteOffset,
141
- response.body.byteLength,
142
- );
143
- } else {
144
- responseBody = JSON.stringify(response.body);
145
- }
146
-
147
- res.writeHead(response.status, responseHeaders);
148
- res.end(responseBody);
149
- }
package/src/index.ts DELETED
@@ -1,152 +0,0 @@
1
- import { CallableMockInstance } from "./builder.js";
2
-
3
- /**
4
- * Create a new Schmock mock instance with callable API.
5
- *
6
- * @example
7
- * ```typescript
8
- * // New callable API (default)
9
- * const mock = schmock({ debug: true })
10
- * mock('GET /users', () => [{ id: 1, name: 'John' }])
11
- * .pipe(authPlugin())
12
- *
13
- * const response = await mock.handle('GET', '/users')
14
- * ```
15
- *
16
- * @example
17
- * ```typescript
18
- * // Simple usage with defaults
19
- * const mock = schmock()
20
- * mock('GET /users', [{ id: 1, name: 'John' }])
21
- * ```
22
- *
23
- * @param config Optional global configuration
24
- * @returns A callable mock instance
25
- */
26
- export function schmock(
27
- config?: Schmock.GlobalConfig,
28
- ): Schmock.CallableMockInstance {
29
- // Always use new callable API
30
- const instance = new CallableMockInstance(config || {});
31
-
32
- // Callable proxy: a function with attached methods
33
- const callableInstance: Schmock.CallableMockInstance = Object.assign(
34
- (
35
- route: Schmock.RouteKey,
36
- generator: Schmock.Generator,
37
- routeConfig: Schmock.RouteConfig = {},
38
- ) => {
39
- instance.defineRoute(route, generator, routeConfig);
40
- return callableInstance;
41
- },
42
- {
43
- pipe: (plugin: Schmock.Plugin) => {
44
- instance.pipe(plugin);
45
- return callableInstance;
46
- },
47
- handle: instance.handle.bind(instance),
48
- history: instance.history.bind(instance),
49
- called: instance.called.bind(instance),
50
- callCount: instance.callCount.bind(instance),
51
- lastRequest: instance.lastRequest.bind(instance),
52
- reset: instance.reset.bind(instance),
53
- resetHistory: instance.resetHistory.bind(instance),
54
- resetState: instance.resetState.bind(instance),
55
- on<E extends Schmock.SchmockEvent>(
56
- event: E,
57
- listener: (data: Schmock.SchmockEventMap[E]) => void,
58
- ) {
59
- instance.on(event, listener);
60
- return callableInstance;
61
- },
62
- off<E extends Schmock.SchmockEvent>(
63
- event: E,
64
- listener: (data: Schmock.SchmockEventMap[E]) => void,
65
- ) {
66
- instance.off(event, listener);
67
- return callableInstance;
68
- },
69
- getRoutes: instance.getRoutes.bind(instance),
70
- getState: instance.getState.bind(instance),
71
- listen: instance.listen.bind(instance),
72
- close: instance.close.bind(instance),
73
- intercept: (options?: Schmock.InterceptOptions) =>
74
- instance.intercept(options),
75
- },
76
- );
77
-
78
- instance.setCallableRef(callableInstance);
79
-
80
- return callableInstance;
81
- }
82
-
83
- export { isBinaryBody } from "./binary.js";
84
- // Re-export constants and utilities
85
- export {
86
- HTTP_METHODS,
87
- isHttpMethod,
88
- isRouteNotFound,
89
- isStatusTuple,
90
- ROUTE_NOT_FOUND_CODE,
91
- toHttpMethod,
92
- toRouteKey,
93
- } from "./constants.js";
94
- // Re-export errors
95
- export {
96
- PluginError,
97
- ResourceLimitError,
98
- ResponseGenerationError,
99
- RouteDefinitionError,
100
- RouteNotFoundError,
101
- RouteParseError,
102
- SchemaGenerationError,
103
- SchemaValidationError,
104
- SchmockError,
105
- } from "./errors.js";
106
- // Re-export response helpers
107
- export {
108
- badRequest,
109
- created,
110
- forbidden,
111
- noContent,
112
- notFound,
113
- paginate,
114
- serverError,
115
- unauthorized,
116
- } from "./helpers.js";
117
- // Re-export HTTP server helpers
118
- export {
119
- collectBody,
120
- parseNodeHeaders,
121
- parseNodeQuery,
122
- writeSchmockResponse,
123
- } from "./http-helpers.js";
124
- // Re-export types
125
- // Re-export interceptor
126
- export { createFetchInterceptor } from "./interceptor.js";
127
- // Re-export types
128
- export type {
129
- AdapterRequest,
130
- AdapterResponse,
131
- CallableMockInstance,
132
- Generator,
133
- GeneratorFunction,
134
- GlobalConfig,
135
- HttpMethod,
136
- InterceptHandle,
137
- InterceptOptions,
138
- Plugin,
139
- PluginContext,
140
- PluginResult,
141
- RequestContext,
142
- RequestOptions,
143
- RequestRecord,
144
- Response,
145
- ResponseBody,
146
- ResponseResult,
147
- RouteConfig,
148
- RouteInfo,
149
- RouteKey,
150
- ServerInfo,
151
- StaticData,
152
- } from "./types.js";