@orval/mock 8.33.0 → 8.34.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/dist/index.d.mts +13 -13
- package/dist/index.mjs +9 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -5,14 +5,14 @@ import { ClientMockGeneratorBuilder, ContextSpec, FakerMockOptions, FinalizeMock
|
|
|
5
5
|
* imports from `msw`, so this only emits `import { faker } from '@faker-js/faker'`
|
|
6
6
|
* (or the locale-scoped variant) plus any operation-specific imports.
|
|
7
7
|
*/
|
|
8
|
-
declare const generateFakerImports: GenerateMockImports;
|
|
8
|
+
export declare const generateFakerImports: GenerateMockImports;
|
|
9
9
|
/**
|
|
10
10
|
* Generates the faker-only mock output for a single operation. This reuses
|
|
11
11
|
* the response-factory portion of {@link generateMSW} and strips out the
|
|
12
12
|
* handler and aggregator entries so callers can write a standalone
|
|
13
13
|
* `<file>.faker.ts` with no `msw` dependency.
|
|
14
14
|
*/
|
|
15
|
-
declare function generateFaker(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: GeneratorOptions): ClientMockGeneratorBuilder;
|
|
15
|
+
export declare function generateFaker(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: GeneratorOptions): ClientMockGeneratorBuilder;
|
|
16
16
|
interface GenerateFakerForSchemasResult {
|
|
17
17
|
implementation: string;
|
|
18
18
|
imports: GeneratorImport[];
|
|
@@ -28,10 +28,10 @@ interface GenerateFakerForSchemasResult {
|
|
|
28
28
|
* Returns the function bodies plus any `GeneratorImport` references the
|
|
29
29
|
* factories need so the writer can hoist them into the file header.
|
|
30
30
|
*/
|
|
31
|
-
declare function generateFakerForSchemas(schemas: GeneratorSchema[], context: ContextSpec, options: GlobalMockOptions): GenerateFakerForSchemasResult;
|
|
31
|
+
export declare function generateFakerForSchemas(schemas: GeneratorSchema[], context: ContextSpec, options: GlobalMockOptions): GenerateFakerForSchemasResult;
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/mock-types.d.ts
|
|
34
|
-
declare function buildStrictMockTypeFileHeader(schemaTypeNames: Iterable<string>, kinds?: Readonly<Record<string, StrictMockSchemaKind$1>>): string;
|
|
34
|
+
export declare function buildStrictMockTypeFileHeader(schemaTypeNames: Iterable<string>, kinds?: Readonly<Record<string, StrictMockSchemaKind$1>>): string;
|
|
35
35
|
/**
|
|
36
36
|
* Prepends shared strict-mock helper types and each `{Schema}Mock` alias once at
|
|
37
37
|
* the top of a mock file. Generators pass `strictSchemaTypeNames`; no scraping.
|
|
@@ -39,34 +39,34 @@ declare function buildStrictMockTypeFileHeader(schemaTypeNames: Iterable<string>
|
|
|
39
39
|
* Not idempotent — callers must invoke this exactly once per aggregated mock
|
|
40
40
|
* file (writers and `writeFakerSchemaMocks`), not from import hooks.
|
|
41
41
|
*/
|
|
42
|
-
declare function dedupeStrictMockTypeDeclarations(implementation: string, options?: FinalizeMockImplementationOptions): string;
|
|
42
|
+
export declare function dedupeStrictMockTypeDeclarations(implementation: string, options?: FinalizeMockImplementationOptions): string;
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/msw/index.d.ts
|
|
45
|
-
declare const generateMSWImports: GenerateMockImports;
|
|
46
|
-
declare function generateMSW(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: GeneratorOptions): ClientMockGeneratorBuilder;
|
|
45
|
+
export declare const generateMSWImports: GenerateMockImports;
|
|
46
|
+
export declare function generateMSW(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: GeneratorOptions): ClientMockGeneratorBuilder;
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region src/index.d.ts
|
|
49
|
-
declare const DEFAULT_MSW_OPTIONS: MswMockOptions;
|
|
50
|
-
declare const DEFAULT_FAKER_OPTIONS: FakerMockOptions;
|
|
49
|
+
export declare const DEFAULT_MSW_OPTIONS: MswMockOptions;
|
|
50
|
+
export declare const DEFAULT_FAKER_OPTIONS: FakerMockOptions;
|
|
51
51
|
/**
|
|
52
52
|
* Returns the default GlobalMockOptions for a given mock type. Used when
|
|
53
53
|
* normalizing user-provided entries in `output.mock.generators` so callers
|
|
54
54
|
* can omit the per-type defaults.
|
|
55
55
|
*/
|
|
56
|
-
declare const getDefaultMockOptionsForType: (type: GlobalMockOptions["type"]) => GlobalMockOptions;
|
|
56
|
+
export declare const getDefaultMockOptionsForType: (type: GlobalMockOptions["type"]) => GlobalMockOptions;
|
|
57
57
|
/**
|
|
58
58
|
* Dispatches mock-file imports generation to the appropriate generator based
|
|
59
59
|
* on the `OutputMockType` discriminator on the mock options.
|
|
60
60
|
*/
|
|
61
|
-
declare const generateMockImports: GenerateMockImports;
|
|
61
|
+
export declare const generateMockImports: GenerateMockImports;
|
|
62
62
|
/**
|
|
63
63
|
* Dispatches per-operation mock generation to the appropriate generator
|
|
64
64
|
* based on the `OutputMockType` discriminator. Each entry in
|
|
65
65
|
* `output.mock.generators` is dispatched here individually.
|
|
66
66
|
*/
|
|
67
|
-
declare function generateMock(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: Omit<GeneratorOptions, 'mock'> & {
|
|
67
|
+
export declare function generateMock(generatorVerbOptions: GeneratorVerbOptions, generatorOptions: Omit<GeneratorOptions, 'mock'> & {
|
|
68
68
|
mock: GlobalMockOptions;
|
|
69
69
|
}): import("@orval/core").ClientMockGeneratorBuilder;
|
|
70
70
|
//#endregion
|
|
71
|
-
export {
|
|
71
|
+
export type { GenerateFakerForSchemasResult };
|
|
72
72
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -45,7 +45,7 @@ function isComposedObjectSchema(schema) {
|
|
|
45
45
|
function getStrictMockTypeDeclaration(typeName, kind = "object", options) {
|
|
46
46
|
const mockTypeName = getStrictMockTypeName(typeName);
|
|
47
47
|
if (kind === "alias") return `export type ${mockTypeName} = ${typeName};`;
|
|
48
|
-
if (kind === "binary") return `export type ${mockTypeName} =
|
|
48
|
+
if (kind === "binary") return `export type ${mockTypeName} = Blob;`;
|
|
49
49
|
const mappedType = `{\n [K in keyof Required<NonNullable<${typeName}>>]: NonNullable<Required<NonNullable<${typeName}>>[K]>;\n}`;
|
|
50
50
|
return `export type ${mockTypeName} = ${options?.schemaNullableAtRoot ? `${mappedType} | null` : mappedType};`;
|
|
51
51
|
}
|
|
@@ -316,7 +316,7 @@ const isFakerVersionV9 = (packageJson) => {
|
|
|
316
316
|
//#region src/faker/constants.ts
|
|
317
317
|
const DEFAULT_FORMAT_MOCK = {
|
|
318
318
|
bic: "faker.finance.bic()",
|
|
319
|
-
binary: "new
|
|
319
|
+
binary: "new Blob([new Uint8Array(faker.number.int({ min: 1, max: 64 }))])",
|
|
320
320
|
city: "faker.location.city()",
|
|
321
321
|
country: "faker.location.country()",
|
|
322
322
|
date: "faker.date.past().toISOString().slice(0, 10)",
|
|
@@ -894,7 +894,7 @@ function getMockScalar({ item, imports, mockOptions, operationId, tags, combine,
|
|
|
894
894
|
overrided: false,
|
|
895
895
|
nullWrapped
|
|
896
896
|
};
|
|
897
|
-
if (item.format && ALL_FORMAT
|
|
897
|
+
if (item.format && Object.hasOwn(ALL_FORMAT, item.format)) {
|
|
898
898
|
let value = ALL_FORMAT[item.format];
|
|
899
899
|
if (["date", "date-time"].includes(item.format) && context.output.override.useDates) value = `new Date(${value})`;
|
|
900
900
|
return {
|
|
@@ -1826,23 +1826,20 @@ function generateDefinition(name, route, getResponseMockFunctionNameBase, handle
|
|
|
1826
1826
|
const isTextResponse = isExactlyStringReturnType && hasTextLikeContentType || contentTypesByPreference.some((ct) => isTextLikeContentType(ct));
|
|
1827
1827
|
const isSchemaBinary = (r) => r.originalSchema?.format === "binary" || r.originalSchema?.contentMediaType === "application/octet-stream" && !r.originalSchema.contentEncoding;
|
|
1828
1828
|
const isBinaryResponse = preferredContentTypeMatch ? responsesByPreference.some((r) => isSchemaBinary(r)) : contentTypesByPreference.some((ct) => isBinaryLikeContentType(ct)) || responsesByPreference.some((r) => isSchemaBinary(r));
|
|
1829
|
-
const binaryRefNames = responsesByPreference.filter((r) => isSchemaBinary(r)).flatMap((r) => r.imports.flatMap((imp) => imp.alias ? [imp.name, imp.alias] : [imp.name]));
|
|
1830
1829
|
const isReturnHttpResponse = value && value !== "undefined";
|
|
1831
1830
|
const getResponseMockFunctionName = `${getResponseMockFunctionNameBase}${pascal(name)}`;
|
|
1832
1831
|
const handlerName = `${handlerNameBase}${pascal(name)}`;
|
|
1833
1832
|
const addedSplitMockImplementations = splitMockImplementations.slice(oldSplitMockImplementations.length);
|
|
1834
1833
|
splitMockImplementations.push(...addedSplitMockImplementations);
|
|
1835
1834
|
const mockImplementations = addedSplitMockImplementations.length > 0 ? `${addedSplitMockImplementations.join("\n\n")}\n\n` : "";
|
|
1836
|
-
const
|
|
1837
|
-
const mockReturnType = isBinaryResponse ? returnType.replaceAll(binaryTypeRewriteRegex, "ArrayBuffer") : returnType;
|
|
1838
|
-
const isVoidUnionType = mockReturnType !== "void" && mockReturnType.split("|").some((part) => part.trim() === "void");
|
|
1835
|
+
const isVoidUnionType = returnType !== "void" && returnType.split("|").some((part) => part.trim() === "void");
|
|
1839
1836
|
const noContentStatusCode = isVoidUnionType ? assertSafeStatusCode(responses.find((r) => r.value === "void")?.key ?? "204") : void 0;
|
|
1840
|
-
const nonVoidMockReturnType = isVoidUnionType ?
|
|
1837
|
+
const nonVoidMockReturnType = isVoidUnionType ? returnType.split("|").filter((part) => part.trim() !== "void").join(" | ").trim() : returnType;
|
|
1841
1838
|
const hasJsonContentType = contentTypesByPreference.some((ct) => ct.includes("json") || ct.includes("+json"));
|
|
1842
|
-
const hasStringReturnType = isTypeExactlyString(
|
|
1839
|
+
const hasStringReturnType = isTypeExactlyString(returnType) || isUnionContainingString(returnType);
|
|
1843
1840
|
const overrideResponseType = `Partial<Extract<${nonVoidMockReturnType}, object>>`;
|
|
1844
1841
|
const shouldPreferJsonResponse = hasJsonContentType && !hasStringReturnType;
|
|
1845
|
-
const needsRuntimeContentTypeSwitch = isTextResponse && hasJsonContentType && hasStringReturnType &&
|
|
1842
|
+
const needsRuntimeContentTypeSwitch = isTextResponse && hasJsonContentType && hasStringReturnType && returnType !== "string";
|
|
1846
1843
|
const mockOptionsFromOverride = override.mock;
|
|
1847
1844
|
const strictMock = isStrictMock(mockOptionsFromOverride);
|
|
1848
1845
|
const schemaTypeNames = strictMock ? getSchemaTypeNamesFromResponses(responses) : [];
|
|
@@ -1890,10 +1887,7 @@ function generateDefinition(name, route, getResponseMockFunctionNameBase, handle
|
|
|
1890
1887
|
if (!isReturnHttpResponse) responseBody = `new HttpResponse(null,
|
|
1891
1888
|
{ status: ${statusCode}
|
|
1892
1889
|
})`;
|
|
1893
|
-
else if (isBinaryResponse) responseBody = `HttpResponse
|
|
1894
|
-
binaryBody instanceof ArrayBuffer
|
|
1895
|
-
? binaryBody
|
|
1896
|
-
: new ArrayBuffer(0),
|
|
1890
|
+
else if (isBinaryResponse) responseBody = `new HttpResponse(binaryBody,
|
|
1897
1891
|
{ status: ${statusCode},
|
|
1898
1892
|
headers: { 'Content-Type': '${jsStringLiteralEscape(binaryContentType)}' }
|
|
1899
1893
|
})`;
|
|
@@ -1920,7 +1914,7 @@ function generateDefinition(name, route, getResponseMockFunctionNameBase, handle
|
|
|
1920
1914
|
})`;
|
|
1921
1915
|
const infoType = `Parameters<Parameters<typeof http.${verb}>[1]>[0]`;
|
|
1922
1916
|
const handlerImplementation = `
|
|
1923
|
-
export const ${handlerName} = (overrideResponse?: ${
|
|
1917
|
+
export const ${handlerName} = (overrideResponse?: ${returnType} | ((${infoParam}: ${infoType}) => Promise<${returnType}> | ${returnType}), options?: RequestHandlerOptions) => {
|
|
1924
1918
|
return http.${verb}('${route}', async (${infoParam}: ${infoType}) => {${delay === false ? "" : `await delay(${isFunction(delay) ? `(${String(delay)})()` : String(delay)});`}
|
|
1925
1919
|
${isReturnHttpResponse ? "" : `if (typeof overrideResponse === 'function') {await overrideResponse(info); }`}
|
|
1926
1920
|
${responsePrelude}
|