@povio/openapi-codegen-cli 3.2.0-rc.8 → 3.2.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/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +1 -1
- package/dist/acl.mjs +3 -2
- package/dist/{auth.context-YFWzkwoN.mjs → auth.context-COWO6ssl.mjs} +1 -19
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/axios.d.mts +2 -0
- package/dist/axios.mjs +2 -0
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-BMXC5P08.mjs → error-handling-BeydPL7s.mjs} +2 -36
- package/dist/{error-handling-CNOHs4Fc.d.mts → error-handling-LPEPQV1V.d.mts} +2 -38
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/{generate.runner-BvSprH6D.mjs → generate.runner-BD9BbYIx.mjs} +9 -32
- package/dist/{generate.utils-CH2U2Dpr.cjs → generate.utils-BqlgVd-i.cjs} +11 -58
- package/dist/{generateCodeFromOpenAPIDoc-CZT3sThI.cjs → generateCodeFromOpenAPIDoc-CkVgg5Zy.cjs} +111 -41
- package/dist/{generateCodeFromOpenAPIDoc-glAKBEGP.mjs → generateCodeFromOpenAPIDoc-idp1RVDa.mjs} +77 -12
- package/dist/generator.mjs +3 -3
- package/dist/{getDataFromOpenAPIDoc-7RxjULpB.mjs → getDataFromOpenAPIDoc-Cyrm3VKA.mjs} +16 -11
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +9 -160
- package/dist/index.mjs +10 -257
- package/dist/metro.cjs +2 -2
- package/dist/metro.mjs +2 -2
- package/dist/{native-rest-interceptor-CAWR8H5Y.mjs → native-rest-interceptor-Np4Ov54n.mjs} +15 -8
- package/dist/{native-rest-interceptor-Cz6saoq5.d.mts → native-rest-interceptor-PgziZt1f.d.mts} +4 -1
- package/dist/native.d.mts +1 -1
- package/dist/native.mjs +1 -1
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-C93V7SGj.mjs → openapi-codegen.runner-BZH4V6rq.mjs} +1 -1
- package/dist/{openapi-source.runner-BZ6ZLgRO.mjs → openapi-source.runner-DPUNTduQ.mjs} +7 -5
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/rest-client-CQyFvqYC.d.mts +55 -0
- package/dist/rest-interceptor-D5NCNTm1.mjs +115 -0
- package/dist/rest.utils-rezWAIYL.d.mts +10 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.mjs +9 -7
- package/dist/tiny.mjs +1 -1
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.mjs +2 -2
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +1 -1
- package/dist/zod.mjs +1 -1
- package/package.json +44 -7
package/dist/{generateCodeFromOpenAPIDoc-CZT3sThI.cjs → generateCodeFromOpenAPIDoc-CkVgg5Zy.cjs}
RENAMED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
const require_generate_utils = require("./generate.utils-
|
|
1
|
+
const require_generate_utils = require("./generate.utils-BqlgVd-i.cjs");
|
|
2
|
+
//#region src/generators/const/acl.const.ts
|
|
3
|
+
const ACL_APP_ABILITY_FILE = {
|
|
4
|
+
fileName: "acl/app.ability",
|
|
5
|
+
extension: "ts"
|
|
6
|
+
};
|
|
7
|
+
const ACL_APP_ABILITIES = "AppAbilities";
|
|
8
|
+
const ACL_CHECK_HOOK = "useAclCheck";
|
|
9
|
+
const CASL_ABILITY_BINDING = {
|
|
10
|
+
abilityTuple: "AbilityTuple",
|
|
11
|
+
pureAbility: "PureAbility",
|
|
12
|
+
forcedSubject: "ForcedSubject",
|
|
13
|
+
subjectType: "Subject",
|
|
14
|
+
subject: "subject"
|
|
15
|
+
};
|
|
16
|
+
const CASL_ABILITY_IMPORT = {
|
|
17
|
+
bindings: [
|
|
18
|
+
CASL_ABILITY_BINDING.abilityTuple,
|
|
19
|
+
CASL_ABILITY_BINDING.pureAbility,
|
|
20
|
+
CASL_ABILITY_BINDING.forcedSubject,
|
|
21
|
+
CASL_ABILITY_BINDING.subjectType,
|
|
22
|
+
CASL_ABILITY_BINDING.subject
|
|
23
|
+
],
|
|
24
|
+
from: "@casl/ability"
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
2
27
|
//#region src/generators/core/zod/getZodChain.ts
|
|
3
28
|
const zodChainCache = /* @__PURE__ */ new WeakMap();
|
|
4
29
|
function getZodChain({ schema, meta, options }) {
|
|
@@ -56,12 +81,14 @@ function formatPatternIfNeeded(pattern) {
|
|
|
56
81
|
function getZodChainableNumberValidations(schema) {
|
|
57
82
|
const validations = [];
|
|
58
83
|
if (schema.enum) return "";
|
|
59
|
-
if (schema.minimum !== void 0)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
if (schema.minimum !== void 0) {
|
|
85
|
+
if (schema.exclusiveMinimum === true) validations.push(`gt(${schema.minimum})`);
|
|
86
|
+
else validations.push(`gte(${schema.minimum})`);
|
|
87
|
+
} else if (typeof schema.exclusiveMinimum === "number") validations.push(`gt(${schema.exclusiveMinimum})`);
|
|
88
|
+
if (schema.maximum !== void 0) {
|
|
89
|
+
if (schema.exclusiveMaximum === true) validations.push(`lt(${schema.maximum})`);
|
|
90
|
+
else validations.push(`lte(${schema.maximum})`);
|
|
91
|
+
} else if (typeof schema.exclusiveMaximum === "number") validations.push(`lt(${schema.exclusiveMaximum})`);
|
|
65
92
|
if (schema.multipleOf) validations.push(`multipleOf(${schema.multipleOf})`);
|
|
66
93
|
return validations.join(".");
|
|
67
94
|
}
|
|
@@ -136,8 +163,10 @@ function getOpenAPISchemaComplexity(current, schema) {
|
|
|
136
163
|
const props = Object.values(schema.properties);
|
|
137
164
|
current += complexityByComposite("object") + sum(props.map((prop) => getOpenAPISchemaComplexity(0, prop)));
|
|
138
165
|
} else current += complexityByComposite("empty-object");
|
|
139
|
-
if (schema.additionalProperties)
|
|
140
|
-
|
|
166
|
+
if (schema.additionalProperties) {
|
|
167
|
+
if (typeof schema.additionalProperties === "object") current += getOpenAPISchemaComplexity(0, schema.additionalProperties);
|
|
168
|
+
else current += getOpenAPISchemaComplexity(1);
|
|
169
|
+
}
|
|
141
170
|
}
|
|
142
171
|
return current;
|
|
143
172
|
}
|
|
@@ -321,7 +350,7 @@ function getZodSchema({ schema, resolver, meta: inheritedMeta, tag }) {
|
|
|
321
350
|
propZodSchema,
|
|
322
351
|
isCircular
|
|
323
352
|
];
|
|
324
|
-
}).map(([prop, propSchema, isCircular]) => isCircular ?
|
|
353
|
+
}).map(([prop, propSchema, isCircular]) => isCircular ? `${require_generate_utils.wrapWithQuotesIfNeeded(prop)}: z.lazy(() => ${propSchema})` : `${require_generate_utils.wrapWithQuotesIfNeeded(prop)}: ${propSchema}`).join(", ")} }`;
|
|
325
354
|
let additionalPropsSchema = "";
|
|
326
355
|
if (schema.additionalProperties) additionalPropsSchema = `.catchall(${typeof schema.additionalProperties === "object" && Object.keys(schema.additionalProperties).length > 0 ? getZodSchema({
|
|
327
356
|
...params,
|
|
@@ -529,7 +558,8 @@ function getEnumZodSchema({ resolver, schema, zodSchema, meta, tag }) {
|
|
|
529
558
|
return zodSchema.assign(`${namespacePrefix}${extractedEnumZodSchema.zodSchemaName}`);
|
|
530
559
|
}
|
|
531
560
|
function getEnumZodSchemaCode(schema) {
|
|
532
|
-
|
|
561
|
+
const values = schema.enum?.filter((value) => value !== null) ?? [];
|
|
562
|
+
return `${require_generate_utils.ENUM_SCHEMA}([${values.map((value) => `"${value}"`).join(", ")}])`;
|
|
533
563
|
}
|
|
534
564
|
function getEnumZodSchemaCodeFromEnumNames(enumNames) {
|
|
535
565
|
return `${require_generate_utils.ENUM_SCHEMA}([${enumNames.map((value) => `"${value}"`).join(", ")}])`;
|
|
@@ -2004,13 +2034,13 @@ function generateAcl({ resolver, data, tag }) {
|
|
|
2004
2034
|
const { hasAdditionalAbilityImports, modelsImports, endpoints } = aclData;
|
|
2005
2035
|
const hasWorkspaceContext = endpoints.some((endpoint) => getWorkspaceConditionNames(resolver, endpoint).length > 0);
|
|
2006
2036
|
const caslAbilityTupleImport = {
|
|
2007
|
-
bindings: [...hasAdditionalAbilityImports ? [
|
|
2008
|
-
typeBindings: [
|
|
2009
|
-
from:
|
|
2037
|
+
bindings: [...hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject, CASL_ABILITY_BINDING.subject] : []],
|
|
2038
|
+
typeBindings: [CASL_ABILITY_BINDING.abilityTuple],
|
|
2039
|
+
from: CASL_ABILITY_IMPORT.from
|
|
2010
2040
|
};
|
|
2011
2041
|
const workspaceContextImport = {
|
|
2012
2042
|
bindings: ["useWorkspaceContext"],
|
|
2013
|
-
from: require_generate_utils.
|
|
2043
|
+
from: require_generate_utils.CONFIG_PACKAGE_IMPORT_PATH
|
|
2014
2044
|
};
|
|
2015
2045
|
const lines = [];
|
|
2016
2046
|
lines.push(renderImport$4(caslAbilityTupleImport));
|
|
@@ -2042,12 +2072,12 @@ function generateAppAcl({ resolver, data }) {
|
|
|
2042
2072
|
const caslAbilityTupleImport = {
|
|
2043
2073
|
bindings: [],
|
|
2044
2074
|
typeBindings: [
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
...!appAbilitiesType ? [
|
|
2048
|
-
...hasAdditionalAbilityImports ? [
|
|
2075
|
+
CASL_ABILITY_BINDING.pureAbility,
|
|
2076
|
+
CASL_ABILITY_BINDING.abilityTuple,
|
|
2077
|
+
...!appAbilitiesType ? [CASL_ABILITY_BINDING.subjectType] : [],
|
|
2078
|
+
...hasAdditionalAbilityImports ? [CASL_ABILITY_BINDING.forcedSubject] : []
|
|
2049
2079
|
],
|
|
2050
|
-
from:
|
|
2080
|
+
from: CASL_ABILITY_IMPORT.from,
|
|
2051
2081
|
typeOnly: true
|
|
2052
2082
|
};
|
|
2053
2083
|
const lines = [];
|
|
@@ -2055,11 +2085,11 @@ function generateAppAcl({ resolver, data }) {
|
|
|
2055
2085
|
for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
|
|
2056
2086
|
lines.push("");
|
|
2057
2087
|
if (appAbilitiesType) {
|
|
2058
|
-
lines.push(`export type ${
|
|
2059
|
-
for (const [action, subjects] of Object.entries(appAbilitiesType)) lines.push(`| ${
|
|
2060
|
-
} else lines.push(`export type ${
|
|
2088
|
+
lines.push(`export type ${ACL_APP_ABILITIES} = `);
|
|
2089
|
+
for (const [action, subjects] of Object.entries(appAbilitiesType)) lines.push(`| ${CASL_ABILITY_BINDING.abilityTuple}<"${action}", ${subjects.join(" | ")}>`);
|
|
2090
|
+
} else lines.push(`export type ${ACL_APP_ABILITIES} = ${CASL_ABILITY_BINDING.abilityTuple}<string, ${CASL_ABILITY_BINDING.subjectType}>;`);
|
|
2061
2091
|
lines.push("");
|
|
2062
|
-
lines.push(`export type AppAbility = PureAbility<${
|
|
2092
|
+
lines.push(`export type AppAbility = PureAbility<${ACL_APP_ABILITIES}>;`);
|
|
2063
2093
|
return lines.join("\n");
|
|
2064
2094
|
}
|
|
2065
2095
|
function renderImport$4(importData) {
|
|
@@ -2118,7 +2148,7 @@ function renderAbilityFunction({ resolver, endpoint }) {
|
|
|
2118
2148
|
lines.push(") => [");
|
|
2119
2149
|
lines.push(` "${require_generate_utils.getAbilityAction(endpoint)}",`);
|
|
2120
2150
|
lines.push(` ${hasConditions ? `object ? subject("${require_generate_utils.getAbilitySubject(endpoint)}", object) : "${require_generate_utils.getAbilitySubject(endpoint)}"` : `"${require_generate_utils.getAbilitySubject(endpoint)}"`}`);
|
|
2121
|
-
lines.push(`] as ${
|
|
2151
|
+
lines.push(`] as ${CASL_ABILITY_BINDING.abilityTuple}<"${require_generate_utils.getAbilityAction(endpoint)}", ${require_generate_utils.getAbilitySubjectTypes(endpoint, resolver, require_generate_utils.getEndpointTag(endpoint, resolver.options)).join(" | ")}>;`);
|
|
2122
2152
|
const workspaceAclHook = renderWorkspaceAclHook({
|
|
2123
2153
|
resolver,
|
|
2124
2154
|
endpoint
|
|
@@ -2160,8 +2190,10 @@ function getBuilderConfigs({ data, tag, resolver }) {
|
|
|
2160
2190
|
if (!columnsConfig) return;
|
|
2161
2191
|
importedEndpoints.push(readAllEndpoint);
|
|
2162
2192
|
importedInfiniteEndpoints.push(readAllEndpoint);
|
|
2163
|
-
if (columnsConfig.zodSchema)
|
|
2164
|
-
|
|
2193
|
+
if (columnsConfig.zodSchema) {
|
|
2194
|
+
if (require_generate_utils.isNamedZodSchema(columnsConfig.zodSchema)) importedZodSchemas.push(columnsConfig.zodSchema);
|
|
2195
|
+
else hasZodImport = true;
|
|
2196
|
+
}
|
|
2165
2197
|
if (columnsConfig.sortableEnumSchemaName) importedZodSchemas.push(columnsConfig.sortableEnumSchemaName);
|
|
2166
2198
|
const filter = readAllEndpoint.parameters.find((param) => param.name === resolver.options.filterParamName);
|
|
2167
2199
|
if (filter) importedZodSchemas.push(filter.zodSchema);
|
|
@@ -2439,7 +2471,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
2439
2471
|
from: require_generate_utils.getQueryModulesImportPath(resolver.options)
|
|
2440
2472
|
};
|
|
2441
2473
|
const aclCheckImport = {
|
|
2442
|
-
bindings: [
|
|
2474
|
+
bindings: [ACL_CHECK_HOOK],
|
|
2443
2475
|
from: resolver.options.aclCheckImportPath
|
|
2444
2476
|
};
|
|
2445
2477
|
const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
|
|
@@ -2534,7 +2566,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
2534
2566
|
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
2535
2567
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
2536
2568
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${require_generate_utils.QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${require_generate_utils.QUERY_MODULE_ENUM}.${tag} });`);
|
|
2537
|
-
if (hasAclCheck) lines.push(` const { checkAcl } = ${
|
|
2569
|
+
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
2538
2570
|
lines.push("");
|
|
2539
2571
|
lines.push(` return ${QUERY_HOOKS.mutation}({`);
|
|
2540
2572
|
const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
|
|
@@ -2777,8 +2809,8 @@ function generateModels({ resolver, data, tag }) {
|
|
|
2777
2809
|
for (const [key, code] of Object.entries(zodSchemas)) {
|
|
2778
2810
|
const schemaRef = resolver.getRefByZodSchemaName(key);
|
|
2779
2811
|
zodSchemasData[key] = {
|
|
2780
|
-
code,
|
|
2781
|
-
|
|
2812
|
+
code: resolver.options.modelsInModules ? code.replace(/\b[A-Z][A-Za-z0-9]*Models\./g, "") : code,
|
|
2813
|
+
isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
|
|
2782
2814
|
isEnum: require_generate_utils.isEnumZodSchema(code),
|
|
2783
2815
|
schemaObj: resolver.getZodSchemaObj(key)
|
|
2784
2816
|
};
|
|
@@ -2799,14 +2831,51 @@ function generateModels({ resolver, data, tag }) {
|
|
|
2799
2831
|
tag,
|
|
2800
2832
|
resolver
|
|
2801
2833
|
}));
|
|
2802
|
-
|
|
2803
|
-
lines.push(`export type ${
|
|
2834
|
+
const inferredTypeName = require_generate_utils.getZodSchemaInferedTypeName(name, resolver.options);
|
|
2835
|
+
if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
|
|
2836
|
+
const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
|
|
2837
|
+
const schemaCode = zodSchema.isCircular ? zodSchema.code : `z.compile(${zodSchema.code})`;
|
|
2838
|
+
lines.push(`export const ${name}${typeAnnotation} = ${schemaCode};`);
|
|
2839
|
+
if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
|
|
2804
2840
|
if (zodSchema.isEnum) lines.push(`export const ${require_generate_utils.getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
|
|
2805
2841
|
lines.push("");
|
|
2806
2842
|
}
|
|
2807
2843
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
2808
2844
|
return lines.join("\n").trimEnd() + "\n";
|
|
2809
2845
|
}
|
|
2846
|
+
function renderSchemaType(schema, resolver) {
|
|
2847
|
+
if (require_generate_utils.isReferenceObject(schema)) {
|
|
2848
|
+
const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
|
|
2849
|
+
return schemaName ? require_generate_utils.getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
|
|
2850
|
+
}
|
|
2851
|
+
const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
|
|
2852
|
+
if (composite?.length) {
|
|
2853
|
+
const separator = schema.allOf ? " & " : " | ";
|
|
2854
|
+
return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
|
|
2855
|
+
}
|
|
2856
|
+
if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
|
|
2857
|
+
if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
|
|
2858
|
+
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
2859
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
|
|
2860
|
+
const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
|
|
2861
|
+
const hasDefault = !require_generate_utils.isReferenceObject(property) && property.default !== void 0;
|
|
2862
|
+
const optional = isRequired || hasDefault ? "" : "?";
|
|
2863
|
+
const propertyType = renderSchemaType(property, resolver);
|
|
2864
|
+
const outputType = resolver.options.replaceOptionalWithNullish && optional && (require_generate_utils.isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
|
|
2865
|
+
return `${require_generate_utils.wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
|
|
2866
|
+
});
|
|
2867
|
+
if (schema.additionalProperties) {
|
|
2868
|
+
const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
|
|
2869
|
+
properties.push(`[key: string]: ${valueType}`);
|
|
2870
|
+
}
|
|
2871
|
+
return addNullable(schema, `{ ${properties.join("; ")} }`);
|
|
2872
|
+
}
|
|
2873
|
+
const primitiveType = schema.type;
|
|
2874
|
+
return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
|
|
2875
|
+
}
|
|
2876
|
+
function addNullable(schema, type) {
|
|
2877
|
+
return schema.nullable && type !== "null" ? `${type} | null` : type;
|
|
2878
|
+
}
|
|
2810
2879
|
function renderModelsProxy({ resolver, data, tag }) {
|
|
2811
2880
|
const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
|
|
2812
2881
|
const schemaNames = getUsedSchemaNames({
|
|
@@ -2952,7 +3021,7 @@ function generateQueries(params) {
|
|
|
2952
3021
|
};
|
|
2953
3022
|
const hasAclCheck = resolver.options.checkAcl && aclEndpoints.length > 0;
|
|
2954
3023
|
const aclCheckImport = {
|
|
2955
|
-
bindings: [
|
|
3024
|
+
bindings: [ACL_CHECK_HOOK],
|
|
2956
3025
|
from: resolver.options.aclCheckImportPath
|
|
2957
3026
|
};
|
|
2958
3027
|
const queryTypesImport = {
|
|
@@ -2967,7 +3036,7 @@ function generateQueries(params) {
|
|
|
2967
3036
|
const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((endpoint) => getWorkspaceParamNames(resolver, endpoint).length > 0);
|
|
2968
3037
|
const workspaceContextImport = {
|
|
2969
3038
|
bindings: ["useWorkspaceContext"],
|
|
2970
|
-
from: require_generate_utils.
|
|
3039
|
+
from: require_generate_utils.CONFIG_PACKAGE_IMPORT_PATH
|
|
2971
3040
|
};
|
|
2972
3041
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
2973
3042
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|
|
@@ -3364,9 +3433,10 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3364
3433
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3365
3434
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
3366
3435
|
lines.push(" initialPageParam: 1,");
|
|
3367
|
-
lines.push(` getNextPageParam: ({ ${resolver.options.infiniteQueryResponseParamNames.page}, ${resolver.options.infiniteQueryResponseParamNames.totalItems}, ${resolver.options.infiniteQueryResponseParamNames.limit}: limitParam }: Awaited<ReturnType<typeof ${endpointFunction}>>) => {`);
|
|
3436
|
+
lines.push(` getNextPageParam: ({ ${resolver.options.infiniteQueryResponseParamNames.page}, ${resolver.options.infiniteQueryResponseParamNames.totalItems}, ${resolver.options.infiniteQueryResponseParamNames.limit}: limitParam }: Awaited<ReturnType<typeof ${endpointFunction}>> & Partial<Record<${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.page)} | ${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.totalItems)} | ${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.limit)}, number | null>>) => {`);
|
|
3368
3437
|
lines.push(` const pageParam = ${resolver.options.infiniteQueryResponseParamNames.page} ?? 1;`);
|
|
3369
|
-
lines.push(
|
|
3438
|
+
lines.push(" const pageSize = limitParam ?? 0;");
|
|
3439
|
+
lines.push(` return pageParam * pageSize < (${resolver.options.infiniteQueryResponseParamNames.totalItems} ?? 0) ? pageParam + 1 : null;`);
|
|
3370
3440
|
lines.push(" },");
|
|
3371
3441
|
lines.push("});");
|
|
3372
3442
|
return lines.join("\n");
|
|
@@ -3422,7 +3492,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3422
3492
|
}));
|
|
3423
3493
|
lines.push(`export const ${require_generate_utils.getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3424
3494
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3425
|
-
if (hasAclCheck) lines.push(` const { checkAcl } = ${
|
|
3495
|
+
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3426
3496
|
lines.push(...renderWorkspaceParamResolutions({
|
|
3427
3497
|
replacements: workspaceParamReplacements,
|
|
3428
3498
|
paramTypes: workspaceParamTypes,
|
|
@@ -3492,7 +3562,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
3492
3562
|
}));
|
|
3493
3563
|
lines.push(`export const ${require_generate_utils.getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3494
3564
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3495
|
-
if (hasAclCheck) lines.push(` const { checkAcl } = ${
|
|
3565
|
+
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3496
3566
|
lines.push(...renderWorkspaceContextDestructure({
|
|
3497
3567
|
replacements: workspaceParamReplacements,
|
|
3498
3568
|
paramTypes: workspaceParamTypes,
|
|
@@ -3611,7 +3681,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3611
3681
|
}));
|
|
3612
3682
|
lines.push(`export const ${require_generate_utils.getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3613
3683
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3614
|
-
if (hasAclCheck) lines.push(` const { checkAcl } = ${
|
|
3684
|
+
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3615
3685
|
lines.push(...renderWorkspaceParamResolutions({
|
|
3616
3686
|
replacements: workspaceParamReplacements,
|
|
3617
3687
|
paramTypes: workspaceParamTypes,
|
|
@@ -3716,7 +3786,7 @@ function getAclFiles(data, resolver) {
|
|
|
3716
3786
|
return [{
|
|
3717
3787
|
fileName: require_generate_utils.getOutputFileName({
|
|
3718
3788
|
output: resolver.options.output,
|
|
3719
|
-
fileName: require_generate_utils.getFileNameWithExtension(
|
|
3789
|
+
fileName: require_generate_utils.getFileNameWithExtension(ACL_APP_ABILITY_FILE)
|
|
3720
3790
|
}),
|
|
3721
3791
|
content: generateAppAcl({
|
|
3722
3792
|
resolver,
|
package/dist/{generateCodeFromOpenAPIDoc-glAKBEGP.mjs → generateCodeFromOpenAPIDoc-idp1RVDa.mjs}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-
|
|
2
|
-
import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as
|
|
1
|
+
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-Cyrm3VKA.mjs";
|
|
2
|
+
import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as NATIVE_RESPONSE_TYPE, At as APP_REST_CLIENT_NAME, B as getPrefetchInfiniteQueryName, Bt as PACKAGE_IMPORT_PATH, C as getAppRestClientImportPath, Cn as ZOD_IMPORT, D as getTagFileName, Dn as AXIOS_REQUEST_CONFIG_TYPE, Dt as isEnumZodSchema, E as getQueryTypesImportPath, En as AXIOS_REQUEST_CONFIG_NAME, F as mergeImports, Ft as QUERY_MODULE_ENUM, G as getAbilityConditionType, H as getQueryName, Ht as getNamespaceName, I as getImportedInfiniteQueryName, In as shouldInlineEndpointsForTag, It as QUERY_OPTIONS_TYPES, J as getAbilityFunctionName, K as getAbilityConditionsTypes, L as getImportedQueryName, Ln as camelToSpaceSeparated, Lt as ZOD_EXTENDED, M as getInfiniteQueriesImports, Mt as DOMAIN_ERRORS_FILE, N as getModelsImports, Nn as getEndpointTag, Nt as MUTATION_EFFECTS, O as getTagImportPath, Ot as isNamedZodSchema, P as getQueriesImports, Pt as QUERY_MODULES_FILE, Q as getAppAbilitiesType, R as getInfiniteQueryName, Rn as capitalize, Rt as CONFIG_PACKAGE_IMPORT_PATH, T as getQueryModulesImportPath, Tn as AXIOS_IMPORT, U as getQueryOptionsName, V as getPrefetchQueryName, Vn as kebabToCamel, Vt as REST_PACKAGE_IMPORT_PATH, W as getAbilityAction, Wn as Profiler, X as getAbilitySubjectTypes, Y as getAbilitySubject, Z as getAclData, Zt as isParamMediaTypeAllowed, _ as hasEndpointConfig, _t as isReadAllEndpoint, an as wrapWithQuotesIfNeeded, at as getZodSchemaInferedTypeName, b as requiresBody, bt as invalidVariableNameCharactersToCamel, c as getDestructuredVariables, cn as isReferenceObject, ct as getSchemaDescriptions, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, et as hasAbilityConditions, f as getEndpointBody, fn as ANY_SCHEMA, ft as getPathSegments, g as getImportedEndpointName, gt as isPathSegmentParam, h as getEndpointPath, ht as isDeleteEndpoint, i as shouldUseNativeCodegen, it as getZodSchemaDescription, j as getImportPath, jn as getRequestConfigTypeName, jt as BUILDERS_UTILS, k as getAclImports, kn as JSON_APPLICATION_FORMAT, kt as APP_REST_CLIENT_FILE, l as isInfiniteQuery, ln as isSchemaObject, m as getEndpointName, mt as isCreateEndpoint, nt as getImportedZodSchemaInferedTypeName, o as getOutputFileName, ot as getZodSchemaPropertyDescriptions, p as getEndpointConfig, pt as isBulkDeleteEndpoint, q as getAbilityDescription, r as compileNativeData, rt as getImportedZodSchemaName, st as getZodSchemaType, tt as renderAclCheckCall, u as isMutation, ut as getUniqueArray, v as mapEndpointParamsToFunctionParams, vt as isReadEndpoint, w as getFileNameWithExtension, wn as AXIOS_DEFAULT_IMPORT_NAME, y as renderMediaUploadMutationBody, yt as isUpdateEndpoint, z as getInfiniteQueryOptionsName, zt as NATIVE_PACKAGE_IMPORT_PATH } from "./generate.runner-BD9BbYIx.mjs";
|
|
3
3
|
import "node:module";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -13,6 +13,31 @@ var __exportAll = (all, no_symbols) => {
|
|
|
13
13
|
return target;
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
|
16
|
+
//#region src/generators/const/acl.const.ts
|
|
17
|
+
const ACL_APP_ABILITY_FILE = {
|
|
18
|
+
fileName: "acl/app.ability",
|
|
19
|
+
extension: "ts"
|
|
20
|
+
};
|
|
21
|
+
const ACL_APP_ABILITIES = "AppAbilities";
|
|
22
|
+
const ACL_CHECK_HOOK = "useAclCheck";
|
|
23
|
+
const CASL_ABILITY_BINDING = {
|
|
24
|
+
abilityTuple: "AbilityTuple",
|
|
25
|
+
pureAbility: "PureAbility",
|
|
26
|
+
forcedSubject: "ForcedSubject",
|
|
27
|
+
subjectType: "Subject",
|
|
28
|
+
subject: "subject"
|
|
29
|
+
};
|
|
30
|
+
const CASL_ABILITY_IMPORT = {
|
|
31
|
+
bindings: [
|
|
32
|
+
CASL_ABILITY_BINDING.abilityTuple,
|
|
33
|
+
CASL_ABILITY_BINDING.pureAbility,
|
|
34
|
+
CASL_ABILITY_BINDING.forcedSubject,
|
|
35
|
+
CASL_ABILITY_BINDING.subjectType,
|
|
36
|
+
CASL_ABILITY_BINDING.subject
|
|
37
|
+
],
|
|
38
|
+
from: "@casl/ability"
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
16
41
|
//#region src/generators/generate/generateAcl.ts
|
|
17
42
|
function generateAcl({ resolver, data, tag }) {
|
|
18
43
|
const nativeContent = resolver.getNativeRenderedAcl?.(tag);
|
|
@@ -32,7 +57,7 @@ function generateAcl({ resolver, data, tag }) {
|
|
|
32
57
|
};
|
|
33
58
|
const workspaceContextImport = {
|
|
34
59
|
bindings: ["useWorkspaceContext"],
|
|
35
|
-
from:
|
|
60
|
+
from: CONFIG_PACKAGE_IMPORT_PATH
|
|
36
61
|
};
|
|
37
62
|
const lines = [];
|
|
38
63
|
lines.push(renderImport$4(caslAbilityTupleImport));
|
|
@@ -182,8 +207,10 @@ function getBuilderConfigs({ data, tag, resolver }) {
|
|
|
182
207
|
if (!columnsConfig) return;
|
|
183
208
|
importedEndpoints.push(readAllEndpoint);
|
|
184
209
|
importedInfiniteEndpoints.push(readAllEndpoint);
|
|
185
|
-
if (columnsConfig.zodSchema)
|
|
186
|
-
|
|
210
|
+
if (columnsConfig.zodSchema) {
|
|
211
|
+
if (isNamedZodSchema(columnsConfig.zodSchema)) importedZodSchemas.push(columnsConfig.zodSchema);
|
|
212
|
+
else hasZodImport = true;
|
|
213
|
+
}
|
|
187
214
|
if (columnsConfig.sortableEnumSchemaName) importedZodSchemas.push(columnsConfig.sortableEnumSchemaName);
|
|
188
215
|
const filter = readAllEndpoint.parameters.find((param) => param.name === resolver.options.filterParamName);
|
|
189
216
|
if (filter) importedZodSchemas.push(filter.zodSchema);
|
|
@@ -799,8 +826,8 @@ function generateModels({ resolver, data, tag }) {
|
|
|
799
826
|
for (const [key, code] of Object.entries(zodSchemas)) {
|
|
800
827
|
const schemaRef = resolver.getRefByZodSchemaName(key);
|
|
801
828
|
zodSchemasData[key] = {
|
|
802
|
-
code,
|
|
803
|
-
|
|
829
|
+
code: resolver.options.modelsInModules ? code.replace(/\b[A-Z][A-Za-z0-9]*Models\./g, "") : code,
|
|
830
|
+
isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
|
|
804
831
|
isEnum: isEnumZodSchema(code),
|
|
805
832
|
schemaObj: resolver.getZodSchemaObj(key)
|
|
806
833
|
};
|
|
@@ -821,14 +848,51 @@ function generateModels({ resolver, data, tag }) {
|
|
|
821
848
|
tag,
|
|
822
849
|
resolver
|
|
823
850
|
}));
|
|
824
|
-
|
|
825
|
-
lines.push(`export type ${
|
|
851
|
+
const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
|
|
852
|
+
if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
|
|
853
|
+
const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
|
|
854
|
+
const schemaCode = zodSchema.isCircular ? zodSchema.code : `z.compile(${zodSchema.code})`;
|
|
855
|
+
lines.push(`export const ${name}${typeAnnotation} = ${schemaCode};`);
|
|
856
|
+
if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
|
|
826
857
|
if (zodSchema.isEnum) lines.push(`export const ${getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
|
|
827
858
|
lines.push("");
|
|
828
859
|
}
|
|
829
860
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
830
861
|
return lines.join("\n").trimEnd() + "\n";
|
|
831
862
|
}
|
|
863
|
+
function renderSchemaType(schema, resolver) {
|
|
864
|
+
if (isReferenceObject(schema)) {
|
|
865
|
+
const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
|
|
866
|
+
return schemaName ? getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
|
|
867
|
+
}
|
|
868
|
+
const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
|
|
869
|
+
if (composite?.length) {
|
|
870
|
+
const separator = schema.allOf ? " & " : " | ";
|
|
871
|
+
return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
|
|
872
|
+
}
|
|
873
|
+
if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
|
|
874
|
+
if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
|
|
875
|
+
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
876
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
|
|
877
|
+
const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
|
|
878
|
+
const hasDefault = !isReferenceObject(property) && property.default !== void 0;
|
|
879
|
+
const optional = isRequired || hasDefault ? "" : "?";
|
|
880
|
+
const propertyType = renderSchemaType(property, resolver);
|
|
881
|
+
const outputType = resolver.options.replaceOptionalWithNullish && optional && (isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
|
|
882
|
+
return `${wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
|
|
883
|
+
});
|
|
884
|
+
if (schema.additionalProperties) {
|
|
885
|
+
const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
|
|
886
|
+
properties.push(`[key: string]: ${valueType}`);
|
|
887
|
+
}
|
|
888
|
+
return addNullable(schema, `{ ${properties.join("; ")} }`);
|
|
889
|
+
}
|
|
890
|
+
const primitiveType = schema.type;
|
|
891
|
+
return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
|
|
892
|
+
}
|
|
893
|
+
function addNullable(schema, type) {
|
|
894
|
+
return schema.nullable && type !== "null" ? `${type} | null` : type;
|
|
895
|
+
}
|
|
832
896
|
function renderModelsProxy({ resolver, data, tag }) {
|
|
833
897
|
const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
|
|
834
898
|
const schemaNames = getUsedSchemaNames({
|
|
@@ -989,7 +1053,7 @@ function generateQueries(params) {
|
|
|
989
1053
|
const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((endpoint) => getWorkspaceParamNames(resolver, endpoint).length > 0);
|
|
990
1054
|
const workspaceContextImport = {
|
|
991
1055
|
bindings: ["useWorkspaceContext"],
|
|
992
|
-
from:
|
|
1056
|
+
from: CONFIG_PACKAGE_IMPORT_PATH
|
|
993
1057
|
};
|
|
994
1058
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
995
1059
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|
|
@@ -1386,9 +1450,10 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1386
1450
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
1387
1451
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
1388
1452
|
lines.push(" initialPageParam: 1,");
|
|
1389
|
-
lines.push(` getNextPageParam: ({ ${resolver.options.infiniteQueryResponseParamNames.page}, ${resolver.options.infiniteQueryResponseParamNames.totalItems}, ${resolver.options.infiniteQueryResponseParamNames.limit}: limitParam }: Awaited<ReturnType<typeof ${endpointFunction}>>) => {`);
|
|
1453
|
+
lines.push(` getNextPageParam: ({ ${resolver.options.infiniteQueryResponseParamNames.page}, ${resolver.options.infiniteQueryResponseParamNames.totalItems}, ${resolver.options.infiniteQueryResponseParamNames.limit}: limitParam }: Awaited<ReturnType<typeof ${endpointFunction}>> & Partial<Record<${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.page)} | ${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.totalItems)} | ${JSON.stringify(resolver.options.infiniteQueryResponseParamNames.limit)}, number | null>>) => {`);
|
|
1390
1454
|
lines.push(` const pageParam = ${resolver.options.infiniteQueryResponseParamNames.page} ?? 1;`);
|
|
1391
|
-
lines.push(
|
|
1455
|
+
lines.push(" const pageSize = limitParam ?? 0;");
|
|
1456
|
+
lines.push(` return pageParam * pageSize < (${resolver.options.infiniteQueryResponseParamNames.totalItems} ?? 0) ? pageParam + 1 : null;`);
|
|
1392
1457
|
lines.push(" },");
|
|
1393
1458
|
lines.push("});");
|
|
1394
1459
|
return lines.join("\n");
|
package/dist/generator.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-
|
|
3
|
-
import { H as getQueryName,
|
|
1
|
+
import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-idp1RVDa.mjs";
|
|
2
|
+
import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-Cyrm3VKA.mjs";
|
|
3
|
+
import { H as getQueryName, Ht as getNamespaceName, Mn as formatTag, O as getTagImportPath, S as getTsTypeBase, Xt as isMediaTypeAllowed, Zt as isParamMediaTypeAllowed, bt as invalidVariableNameCharactersToCamel, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, t as getOpenApiDoc, u as isMutation, x as getSchemaTsMetaType } from "./generate.runner-BD9BbYIx.mjs";
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
|
5
5
|
async function getMetadataFromOpenAPIDoc(openApiDoc, options) {
|
|
6
6
|
const { resolver, data } = await getDataFromOpenAPIDoc(openApiDoc, options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as isPrimitiveType, Bn as getMostCommonAdjacentCombinationSplit, Ct as getParamZodSchemaName, Et as getZodSchemaOperationName, Fn as isTagIncluded, Gt as getParameterEnumNames, Hn as removeWord, Ht as getNamespaceName, Jt as isErrorStatus, Kt as getSchemaNameByRef, Mn as formatTag, Nn as getEndpointTag, On as BODY_PARAMETER_NAME, Ot as isNamedZodSchema, Pn as getOperationTag, Qt as isPathExcluded, Rn as capitalize, Sn as VOID_SCHEMA, St as getEnumZodSchemaName, Tt as getZodSchemaName, Un as snakeToCamel, Ut as autocorrectRef, Wn as Profiler, Wt as escapeControlCharacters, Xt as isMediaTypeAllowed, Yt as isMainResponseStatus, Zt as isParamMediaTypeAllowed, _n as INT_SCHEMA, an as wrapWithQuotesIfNeeded, bn as URL_SCHEMA, bt as invalidVariableNameCharactersToCamel, cn as isReferenceObject, d as isQuery, dn as ALLOWED_PATH_IN, en as isSortingParameterObject, fn as ANY_SCHEMA, gn as ENUM_SCHEMA, hn as EMAIL_SCHEMA, in as unwrapQuotesIfNeeded, kn as JSON_APPLICATION_FORMAT, ln as isSchemaObject, lt as iterateSchema, mn as DATETIME_SCHEMA, nn as pathToVariableName, on as inferRequiredSchema, pn as BLOB_SCHEMA, qt as getSchemaRef, rn as replaceHyphenatedPath, s as pick, sn as isArraySchemaObject, tn as pathParamToVariableName, un as ALLOWED_METHODS, ut as getUniqueArray, vn as NUMBER_SCHEMA, wt as getResponseZodSchemaName, xn as UUID_SCHEMA, xt as getBodyZodSchemaName, yn as STRING_SCHEMA, zn as decapitalize } from "./generate.runner-BD9BbYIx.mjs";
|
|
2
2
|
//#region src/generators/const/validation.const.ts
|
|
3
3
|
const HTTP_STATUS_CODES = {
|
|
4
4
|
"100": "Continue",
|
|
@@ -119,12 +119,14 @@ function formatPatternIfNeeded(pattern) {
|
|
|
119
119
|
function getZodChainableNumberValidations(schema) {
|
|
120
120
|
const validations = [];
|
|
121
121
|
if (schema.enum) return "";
|
|
122
|
-
if (schema.minimum !== void 0)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
if (schema.minimum !== void 0) {
|
|
123
|
+
if (schema.exclusiveMinimum === true) validations.push(`gt(${schema.minimum})`);
|
|
124
|
+
else validations.push(`gte(${schema.minimum})`);
|
|
125
|
+
} else if (typeof schema.exclusiveMinimum === "number") validations.push(`gt(${schema.exclusiveMinimum})`);
|
|
126
|
+
if (schema.maximum !== void 0) {
|
|
127
|
+
if (schema.exclusiveMaximum === true) validations.push(`lt(${schema.maximum})`);
|
|
128
|
+
else validations.push(`lte(${schema.maximum})`);
|
|
129
|
+
} else if (typeof schema.exclusiveMaximum === "number") validations.push(`lt(${schema.exclusiveMaximum})`);
|
|
128
130
|
if (schema.multipleOf) validations.push(`multipleOf(${schema.multipleOf})`);
|
|
129
131
|
return validations.join(".");
|
|
130
132
|
}
|
|
@@ -199,8 +201,10 @@ function getOpenAPISchemaComplexity(current, schema) {
|
|
|
199
201
|
const props = Object.values(schema.properties);
|
|
200
202
|
current += complexityByComposite("object") + sum(props.map((prop) => getOpenAPISchemaComplexity(0, prop)));
|
|
201
203
|
} else current += complexityByComposite("empty-object");
|
|
202
|
-
if (schema.additionalProperties)
|
|
203
|
-
|
|
204
|
+
if (schema.additionalProperties) {
|
|
205
|
+
if (typeof schema.additionalProperties === "object") current += getOpenAPISchemaComplexity(0, schema.additionalProperties);
|
|
206
|
+
else current += getOpenAPISchemaComplexity(1);
|
|
207
|
+
}
|
|
204
208
|
}
|
|
205
209
|
return current;
|
|
206
210
|
}
|
|
@@ -384,7 +388,7 @@ function getZodSchema({ schema, resolver, meta: inheritedMeta, tag }) {
|
|
|
384
388
|
propZodSchema,
|
|
385
389
|
isCircular
|
|
386
390
|
];
|
|
387
|
-
}).map(([prop, propSchema, isCircular]) => isCircular ?
|
|
391
|
+
}).map(([prop, propSchema, isCircular]) => isCircular ? `${wrapWithQuotesIfNeeded(prop)}: z.lazy(() => ${propSchema})` : `${wrapWithQuotesIfNeeded(prop)}: ${propSchema}`).join(", ")} }`;
|
|
388
392
|
let additionalPropsSchema = "";
|
|
389
393
|
if (schema.additionalProperties) additionalPropsSchema = `.catchall(${typeof schema.additionalProperties === "object" && Object.keys(schema.additionalProperties).length > 0 ? getZodSchema({
|
|
390
394
|
...params,
|
|
@@ -592,7 +596,8 @@ function getEnumZodSchema({ resolver, schema, zodSchema, meta, tag }) {
|
|
|
592
596
|
return zodSchema.assign(`${namespacePrefix}${extractedEnumZodSchema.zodSchemaName}`);
|
|
593
597
|
}
|
|
594
598
|
function getEnumZodSchemaCode(schema) {
|
|
595
|
-
|
|
599
|
+
const values = schema.enum?.filter((value) => value !== null) ?? [];
|
|
600
|
+
return `${ENUM_SCHEMA}([${values.map((value) => `"${value}"`).join(", ")}])`;
|
|
596
601
|
}
|
|
597
602
|
function getEnumZodSchemaCodeFromEnumNames(enumNames) {
|
|
598
603
|
return `${ENUM_SCHEMA}([${enumNames.map((value) => `"${value}"`).join(", ")}])`;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/lib/config/i18n.d.ts
|
|
2
|
+
declare const ns = "openapi";
|
|
3
|
+
declare const resources: {
|
|
4
|
+
readonly en: {
|
|
5
|
+
readonly openapi: {
|
|
6
|
+
openapi: {
|
|
7
|
+
sharedErrors: {
|
|
8
|
+
dataValidation: string;
|
|
9
|
+
internalError: string;
|
|
10
|
+
networkError: string;
|
|
11
|
+
canceledError: string;
|
|
12
|
+
unknownError: string;
|
|
13
|
+
unknownErrorWithCode: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly sl: {
|
|
19
|
+
readonly openapi: {
|
|
20
|
+
openapi: {
|
|
21
|
+
sharedErrors: {
|
|
22
|
+
dataValidation: string;
|
|
23
|
+
internalError: string;
|
|
24
|
+
networkError: string;
|
|
25
|
+
canceledError: string;
|
|
26
|
+
unknownError: string;
|
|
27
|
+
unknownErrorWithCode: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type TranslateFunction = (key: string, options?: {
|
|
34
|
+
ns?: string;
|
|
35
|
+
}) => string;
|
|
36
|
+
declare function configureTranslations<T>(getter: () => T): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { resources as i, configureTranslations as n, ns as r, TranslateFunction as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/lib/assets/locales/en/translation.json
|
|
2
|
+
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
3
|
+
"dataValidation": "An error occurred while validating the data",
|
|
4
|
+
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
5
|
+
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
6
|
+
"canceledError": "The request was canceled.",
|
|
7
|
+
"unknownError": "An unknown error occurred. Please try again later.",
|
|
8
|
+
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
9
|
+
} } };
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/lib/assets/locales/sl/translation.json
|
|
12
|
+
var translation_default = { openapi: { "sharedErrors": {
|
|
13
|
+
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
14
|
+
"internalError": "Prišlo je do notranje napake.",
|
|
15
|
+
"networkError": "Prišlo je do napake v omrežju.",
|
|
16
|
+
"canceledError": "Zahteva je bila preklicana.",
|
|
17
|
+
"unknownError": "Prišlo je do neznane napake.",
|
|
18
|
+
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
19
|
+
} } };
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/lib/config/i18n.ts
|
|
22
|
+
const ns = "openapi";
|
|
23
|
+
const resources = {
|
|
24
|
+
en: { [ns]: translation_default$1 },
|
|
25
|
+
sl: { [ns]: translation_default }
|
|
26
|
+
};
|
|
27
|
+
let getT = null;
|
|
28
|
+
function configureTranslations(getter) {
|
|
29
|
+
getT = () => getter();
|
|
30
|
+
}
|
|
31
|
+
function resolveT() {
|
|
32
|
+
if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
|
|
33
|
+
return getT();
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { resources as i, ns as n, resolveT as r, configureTranslations as t };
|