@povio/openapi-codegen-cli 4.0.0-rc.3 → 4.0.0-rc.4
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 +0 -1
- package/dist/{config-CiLFKLAY.d.mts → config-BSYiW3xV.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/{generate.runner-Sh0Ps6AW.mjs → generate.runner-BMqvEp4L.mjs} +6 -110
- package/dist/{generate.utils-BJxdEik8.cjs → generate.utils-D4eHo3wO.cjs} +3 -269
- package/dist/{generateCodeFromOpenAPIDoc-Bbi8fYi2.cjs → generateCodeFromOpenAPIDoc-DRLE112u.cjs} +100 -528
- package/dist/{generateCodeFromOpenAPIDoc-B8FAsxWE.mjs → generateCodeFromOpenAPIDoc-oe5uj0P4.mjs} +57 -502
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +3 -3
- package/dist/{getDataFromOpenAPIDoc-CXYNMMMt.mjs → getDataFromOpenAPIDoc-BqEeVt1w.mjs} +19 -2
- package/dist/index.d.mts +4 -4
- package/dist/metro.cjs +3 -3
- package/dist/metro.d.mts +3 -3
- package/dist/metro.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-bJTFHTdn.mjs → openapi-codegen.runner-R_Dnb1mt.mjs} +1 -1
- package/dist/{openapi-source.runner-DIOvAX_R.d.mts → openapi-source.runner-DEtp4qCv.d.mts} +1 -1
- package/dist/{options-X0zju7gw.d.mts → options-BV720uS2.d.mts} +2 -10
- package/dist/query.d.mts +3 -3
- package/dist/{queryConfig.context-DjhzewdL.d.mts → queryConfig.context-BbLtDfIH.d.mts} +19 -9
- package/dist/sh.mjs +3 -8
- package/dist/tiny.d.mts +1 -1
- package/dist/{useMutationEffects-CJJuL9Ak.d.mts → useMutationEffects-CmGB4BOV.d.mts} +1 -1
- package/dist/vite.d.mts +3 -3
- package/dist/vite.mjs +1 -1
- package/package.json +1 -1
package/dist/{generateCodeFromOpenAPIDoc-Bbi8fYi2.cjs → generateCodeFromOpenAPIDoc-DRLE112u.cjs}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const require_generate_utils = require("./generate.utils-
|
|
1
|
+
const require_generate_utils = require("./generate.utils-D4eHo3wO.cjs");
|
|
2
|
+
let openapi_types = require("openapi-types");
|
|
2
3
|
//#region src/generators/const/acl.const.ts
|
|
3
4
|
const ACL_APP_ABILITY_FILE = {
|
|
4
5
|
fileName: "acl/app.ability",
|
|
@@ -24,6 +25,22 @@ const CASL_ABILITY_IMPORT = {
|
|
|
24
25
|
from: "@casl/ability"
|
|
25
26
|
};
|
|
26
27
|
//#endregion
|
|
28
|
+
//#region src/generators/utils/endpoint.utils.ts
|
|
29
|
+
const isGetEndpoint = (endpoint) => endpoint.method === openapi_types.OpenAPIV3.HttpMethods.GET;
|
|
30
|
+
const isPaginatedGetEndpoint = (endpoint, options) => isGetEndpoint(endpoint) && Object.values(options.infiniteQueryParamNames).every((infiniteQueryParam) => endpoint.parameters.some((param) => param.name === infiniteQueryParam && param.type === "Query"));
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/generators/utils/query.utils.ts
|
|
33
|
+
const isQuery = (endpoint) => isGetEndpoint(endpoint);
|
|
34
|
+
const isMutation = (endpoint) => !isGetEndpoint(endpoint) || !!endpoint.mediaDownload;
|
|
35
|
+
const isInfiniteQuery = (endpoint, options) => isPaginatedGetEndpoint(endpoint, options);
|
|
36
|
+
const getDestructuredVariables = (resolver, endpoint, updateQueryEndpoints) => {
|
|
37
|
+
const requiredUpdateQueryParams = updateQueryEndpoints.reduce((acc, updateEndpoint) => [...acc, ...require_generate_utils.mapEndpointParamsToFunctionParams(resolver, updateEndpoint, { includeOnlyRequiredParams: true }).map((param) => param.name)], []);
|
|
38
|
+
return require_generate_utils.mapEndpointParamsToFunctionParams(resolver, endpoint, {
|
|
39
|
+
includeOnlyRequiredParams: true,
|
|
40
|
+
excludeBodyParam: true
|
|
41
|
+
}).filter((param) => requiredUpdateQueryParams.includes(param.name)).map((param) => param.name);
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
27
44
|
//#region src/generators/core/zod/getZodChain.ts
|
|
28
45
|
const zodChainCache = /* @__PURE__ */ new WeakMap();
|
|
29
46
|
function getZodChain({ schema, meta, options }) {
|
|
@@ -758,7 +775,7 @@ function getEndpointAclConditionPropertyType({ resolver, endpoint, acl, name })
|
|
|
758
775
|
if (matchingMediaType) {
|
|
759
776
|
schema = bodyParameter?.bodyObject?.content?.[matchingMediaType]?.schema;
|
|
760
777
|
required = bodyParameter?.bodyObject?.required;
|
|
761
|
-
info = `${
|
|
778
|
+
info = `${isQuery(endpoint) ? "query" : "mutation"} data`;
|
|
762
779
|
if (pathSplits[index]?.startsWith("$")) index++;
|
|
763
780
|
}
|
|
764
781
|
}
|
|
@@ -1144,7 +1161,7 @@ function isOperationExcluded(operation, options) {
|
|
|
1144
1161
|
const isIncluded = require_generate_utils.isTagIncluded(tag, options);
|
|
1145
1162
|
return isDeprecated || !isIncluded;
|
|
1146
1163
|
}
|
|
1147
|
-
function getOperationName({ path, method, operation, options, tag, keepOperationTag, keepOperationPrefix }) {
|
|
1164
|
+
function getOperationName$1({ path, method, operation, options, tag, keepOperationTag, keepOperationPrefix }) {
|
|
1148
1165
|
return resolveOperationName({
|
|
1149
1166
|
path,
|
|
1150
1167
|
method,
|
|
@@ -1210,13 +1227,13 @@ function getUniqueOperationName({ operationsByTag, nameIndexes, ...params }) {
|
|
|
1210
1227
|
const { operation, options } = params;
|
|
1211
1228
|
const tag = options.splitByTags ? require_generate_utils.getOperationTag(operation, options) : options.defaultTag;
|
|
1212
1229
|
const operationName = (keepOperationTag, nameIndex) => {
|
|
1213
|
-
const name = getOperationName({
|
|
1230
|
+
const name = getOperationName$1({
|
|
1214
1231
|
...params,
|
|
1215
1232
|
tag,
|
|
1216
1233
|
keepOperationTag
|
|
1217
1234
|
});
|
|
1218
1235
|
if (nameIndex) {
|
|
1219
|
-
const pathSourceMatches = nameIndex.pathSourceCount > 0 && getOperationName({
|
|
1236
|
+
const pathSourceMatches = nameIndex.pathSourceCount > 0 && getOperationName$1({
|
|
1220
1237
|
...params,
|
|
1221
1238
|
operation: {},
|
|
1222
1239
|
tag,
|
|
@@ -1226,7 +1243,7 @@ function getUniqueOperationName({ operationsByTag, nameIndexes, ...params }) {
|
|
|
1226
1243
|
return (nameIndex.stableCounts.get(name) ?? 0) + (pathSourceMatches ? nameIndex.pathSourceCount : 0) + (pathFallbackMatches ? nameIndex.reservedFallbackCount : 0) === 1 ? name : void 0;
|
|
1227
1244
|
}
|
|
1228
1245
|
let matchingOperations = 0;
|
|
1229
|
-
for (const candidate of operationsByTag[tag]) if (getOperationName({
|
|
1246
|
+
for (const candidate of operationsByTag[tag]) if (getOperationName$1({
|
|
1230
1247
|
...params,
|
|
1231
1248
|
operation: candidate,
|
|
1232
1249
|
tag,
|
|
@@ -1237,7 +1254,7 @@ function getUniqueOperationName({ operationsByTag, nameIndexes, ...params }) {
|
|
|
1237
1254
|
}
|
|
1238
1255
|
if (matchingOperations === 1) return name;
|
|
1239
1256
|
};
|
|
1240
|
-
return operationName(void 0, nameIndexes?.[0]) ?? operationName(true, nameIndexes?.[1]) ?? getOperationName({
|
|
1257
|
+
return operationName(void 0, nameIndexes?.[0]) ?? operationName(true, nameIndexes?.[1]) ?? getOperationName$1({
|
|
1241
1258
|
...params,
|
|
1242
1259
|
tag,
|
|
1243
1260
|
keepOperationTag: true,
|
|
@@ -2021,6 +2038,35 @@ function getTagElement$1(tag, data) {
|
|
|
2021
2038
|
return data.get(tag);
|
|
2022
2039
|
}
|
|
2023
2040
|
//#endregion
|
|
2041
|
+
//#region src/generators/utils/generate/generate.query.utils.ts
|
|
2042
|
+
const operationNameByEndpoint = /* @__PURE__ */ new WeakMap();
|
|
2043
|
+
const capitalizedOperationNameByEndpoint = /* @__PURE__ */ new WeakMap();
|
|
2044
|
+
function getOperationName(endpoint) {
|
|
2045
|
+
let name = operationNameByEndpoint.get(endpoint);
|
|
2046
|
+
if (name === void 0) {
|
|
2047
|
+
name = require_generate_utils.snakeToCamel(endpoint.operationName);
|
|
2048
|
+
operationNameByEndpoint.set(endpoint, name);
|
|
2049
|
+
}
|
|
2050
|
+
return name;
|
|
2051
|
+
}
|
|
2052
|
+
function getCapitalizedOperationName(endpoint) {
|
|
2053
|
+
let name = capitalizedOperationNameByEndpoint.get(endpoint);
|
|
2054
|
+
if (name === void 0) {
|
|
2055
|
+
name = require_generate_utils.capitalize(getOperationName(endpoint));
|
|
2056
|
+
capitalizedOperationNameByEndpoint.set(endpoint, name);
|
|
2057
|
+
}
|
|
2058
|
+
return name;
|
|
2059
|
+
}
|
|
2060
|
+
const getQueryName = (endpoint, mutation) => {
|
|
2061
|
+
const addMutationSuffix = isQuery(endpoint) && isMutation(endpoint) && mutation;
|
|
2062
|
+
return `use${getCapitalizedOperationName(endpoint)}${addMutationSuffix ? "Mutation" : ""}`;
|
|
2063
|
+
};
|
|
2064
|
+
const getInfiniteQueryName = (endpoint) => `use${getCapitalizedOperationName(endpoint)}Infinite`;
|
|
2065
|
+
const getQueryOptionsName = (endpoint) => `${getOperationName(endpoint)}QueryOptions`;
|
|
2066
|
+
const getInfiniteQueryOptionsName = (endpoint) => `${getOperationName(endpoint)}InfiniteQueryOptions`;
|
|
2067
|
+
const getPrefetchQueryName = (endpoint) => `prefetch${getCapitalizedOperationName(endpoint)}`;
|
|
2068
|
+
const getPrefetchInfiniteQueryName = (endpoint) => `prefetch${getCapitalizedOperationName(endpoint)}Infinite`;
|
|
2069
|
+
//#endregion
|
|
2024
2070
|
//#region src/generators/generate/generateAcl.ts
|
|
2025
2071
|
function generateAcl({ resolver, data, tag }) {
|
|
2026
2072
|
const nativeContent = resolver.getNativeRenderedAcl?.(tag);
|
|
@@ -2043,9 +2089,9 @@ function generateAcl({ resolver, data, tag }) {
|
|
|
2043
2089
|
from: require_generate_utils.CONFIG_PACKAGE_IMPORT_PATH
|
|
2044
2090
|
};
|
|
2045
2091
|
const lines = [];
|
|
2046
|
-
lines.push(renderImport$
|
|
2047
|
-
if (hasWorkspaceContext) lines.push(renderImport$
|
|
2048
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
2092
|
+
lines.push(renderImport$3(caslAbilityTupleImport));
|
|
2093
|
+
if (hasWorkspaceContext) lines.push(renderImport$3(workspaceContextImport));
|
|
2094
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
|
|
2049
2095
|
lines.push("");
|
|
2050
2096
|
if (resolver.options.tsNamespaces) lines.push(`export namespace ${require_generate_utils.getNamespaceName({
|
|
2051
2097
|
type: "acl",
|
|
@@ -2081,8 +2127,8 @@ function generateAppAcl({ resolver, data }) {
|
|
|
2081
2127
|
typeOnly: true
|
|
2082
2128
|
};
|
|
2083
2129
|
const lines = [];
|
|
2084
|
-
lines.push(renderImport$
|
|
2085
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$
|
|
2130
|
+
lines.push(renderImport$3(caslAbilityTupleImport));
|
|
2131
|
+
for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
|
|
2086
2132
|
lines.push("");
|
|
2087
2133
|
if (appAbilitiesType) {
|
|
2088
2134
|
lines.push(`export type ${ACL_APP_ABILITIES} = `);
|
|
@@ -2092,7 +2138,7 @@ function generateAppAcl({ resolver, data }) {
|
|
|
2092
2138
|
lines.push(`export type AppAbility = PureAbility<${ACL_APP_ABILITIES}>;`);
|
|
2093
2139
|
return lines.join("\n");
|
|
2094
2140
|
}
|
|
2095
|
-
function renderImport$
|
|
2141
|
+
function renderImport$3(importData) {
|
|
2096
2142
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
2097
2143
|
const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
|
|
2098
2144
|
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
|
|
@@ -2136,7 +2182,7 @@ function renderAbilityFunction({ resolver, endpoint }) {
|
|
|
2136
2182
|
const abilityConditionsTypes = require_generate_utils.getAbilityConditionsTypes(endpoint) ?? [];
|
|
2137
2183
|
const hasConditions = require_generate_utils.hasAbilityConditions(endpoint);
|
|
2138
2184
|
const lines = [];
|
|
2139
|
-
const abilityQuery = endpoint.method === "get" ? endpoint.mediaDownload ? `\`${
|
|
2185
|
+
const abilityQuery = endpoint.method === "get" ? endpoint.mediaDownload ? `\`${getQueryName(endpoint)}\` query or \`${getQueryName(endpoint, true)}\` mutation` : `\`${getQueryName(endpoint)}\` query` : `\`${getQueryName(endpoint)}\` mutation`;
|
|
2140
2186
|
lines.push("/**");
|
|
2141
2187
|
lines.push(` * Use for ${abilityQuery} ability. ${hasConditions ? "For global ability, omit the object parameter." : ""}${require_generate_utils.getAbilityDescription(endpoint) ? "" : ""}`);
|
|
2142
2188
|
if (require_generate_utils.getAbilityDescription(endpoint)) lines.push(` * @description ${require_generate_utils.getAbilityDescription(endpoint)}`);
|
|
@@ -2163,495 +2209,6 @@ function renderConditionType(resolver, endpoint, propertyType) {
|
|
|
2163
2209
|
return require_generate_utils.getAbilityConditionType(propertyType, resolver, require_generate_utils.getEndpointTag(endpoint, resolver.options));
|
|
2164
2210
|
}
|
|
2165
2211
|
//#endregion
|
|
2166
|
-
//#region src/generators/const/buildConfigs.const.ts
|
|
2167
|
-
const BUILD_CONFIG_SUFFIX = "config";
|
|
2168
|
-
//#endregion
|
|
2169
|
-
//#region src/generators/utils/generate/generate.configs.utils.ts
|
|
2170
|
-
function getBuilderConfigs({ data, tag, resolver }) {
|
|
2171
|
-
const endpoints = data.get(tag)?.endpoints;
|
|
2172
|
-
if (!endpoints || endpoints.length === 0) return {
|
|
2173
|
-
configs: [],
|
|
2174
|
-
hasZodImport: false,
|
|
2175
|
-
modelsImports: [],
|
|
2176
|
-
queriesImports: [],
|
|
2177
|
-
aclImports: []
|
|
2178
|
-
};
|
|
2179
|
-
const extendedEndpoints = endpoints.map((endpoint) => ({
|
|
2180
|
-
...endpoint,
|
|
2181
|
-
pathSegments: require_generate_utils.getPathSegments(endpoint.path)
|
|
2182
|
-
}));
|
|
2183
|
-
const namedReadAllEndpoints = resolveBuilderConfigNames(extendedEndpoints.filter((endpoint) => require_generate_utils.isReadAllEndpoint(endpoint, resolver.options)));
|
|
2184
|
-
let hasZodImport = false;
|
|
2185
|
-
const importedZodSchemas = [];
|
|
2186
|
-
const importedEndpoints = [];
|
|
2187
|
-
const importedInfiniteEndpoints = [];
|
|
2188
|
-
const configs = Object.entries(namedReadAllEndpoints).map(([name, readAllEndpoint]) => {
|
|
2189
|
-
const columnsConfig = getColumnsConfig(resolver, readAllEndpoint);
|
|
2190
|
-
if (!columnsConfig) return;
|
|
2191
|
-
importedEndpoints.push(readAllEndpoint);
|
|
2192
|
-
importedInfiniteEndpoints.push(readAllEndpoint);
|
|
2193
|
-
if (columnsConfig.zodSchema) {
|
|
2194
|
-
if (require_generate_utils.isNamedZodSchema(columnsConfig.zodSchema)) importedZodSchemas.push(columnsConfig.zodSchema);
|
|
2195
|
-
else hasZodImport = true;
|
|
2196
|
-
}
|
|
2197
|
-
if (columnsConfig.sortableEnumSchemaName) importedZodSchemas.push(columnsConfig.sortableEnumSchemaName);
|
|
2198
|
-
const filter = readAllEndpoint.parameters.find((param) => param.name === resolver.options.filterParamName);
|
|
2199
|
-
if (filter) importedZodSchemas.push(filter.zodSchema);
|
|
2200
|
-
const config = {
|
|
2201
|
-
name,
|
|
2202
|
-
title: require_generate_utils.capitalize(require_generate_utils.camelToSpaceSeparated(name.replace(/config$/i, ""))),
|
|
2203
|
-
readAll: {
|
|
2204
|
-
acl: getAclConfig(readAllEndpoint, resolver.options),
|
|
2205
|
-
paginated: require_generate_utils.getImportedQueryName(readAllEndpoint, resolver.options),
|
|
2206
|
-
infinite: resolver.options.infiniteQueries ? require_generate_utils.getImportedInfiniteQueryName(readAllEndpoint, resolver.options) : void 0,
|
|
2207
|
-
filters: getInputsConfig(resolver, filter),
|
|
2208
|
-
columns: columnsConfig.columns
|
|
2209
|
-
}
|
|
2210
|
-
};
|
|
2211
|
-
const readEndpoint = extendedEndpoints.find((endpoint) => require_generate_utils.isReadEndpoint(endpoint, readAllEndpoint));
|
|
2212
|
-
if (readEndpoint) {
|
|
2213
|
-
importedEndpoints.push(readEndpoint);
|
|
2214
|
-
let responseSchema = readEndpoint.response;
|
|
2215
|
-
if (require_generate_utils.isNamedZodSchema(responseSchema)) {
|
|
2216
|
-
importedZodSchemas.push(responseSchema);
|
|
2217
|
-
responseSchema = require_generate_utils.getImportedZodSchemaName(resolver, responseSchema);
|
|
2218
|
-
} else hasZodImport = true;
|
|
2219
|
-
config.read = {
|
|
2220
|
-
acl: getAclConfig(readEndpoint, resolver.options),
|
|
2221
|
-
schema: responseSchema,
|
|
2222
|
-
query: require_generate_utils.getImportedQueryName(readEndpoint, resolver.options)
|
|
2223
|
-
};
|
|
2224
|
-
}
|
|
2225
|
-
const createEndpoint = extendedEndpoints.find((endpoint) => require_generate_utils.isCreateEndpoint(endpoint, readAllEndpoint));
|
|
2226
|
-
if (createEndpoint) {
|
|
2227
|
-
importedEndpoints.push(createEndpoint);
|
|
2228
|
-
const body = require_generate_utils.getEndpointBody(createEndpoint);
|
|
2229
|
-
if (body) {
|
|
2230
|
-
importedZodSchemas.push(body.zodSchema);
|
|
2231
|
-
config.create = {
|
|
2232
|
-
acl: getAclConfig(createEndpoint, resolver.options),
|
|
2233
|
-
schema: require_generate_utils.getImportedZodSchemaName(resolver, body.zodSchema),
|
|
2234
|
-
mutation: createEndpoint,
|
|
2235
|
-
inputDefs: getInputsConfig(resolver, body)
|
|
2236
|
-
};
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
const updateEndpoint = extendedEndpoints.find((endpoint) => require_generate_utils.isUpdateEndpoint(endpoint, readAllEndpoint));
|
|
2240
|
-
if (updateEndpoint) {
|
|
2241
|
-
importedEndpoints.push(updateEndpoint);
|
|
2242
|
-
const body = require_generate_utils.getEndpointBody(updateEndpoint);
|
|
2243
|
-
if (body) {
|
|
2244
|
-
importedZodSchemas.push(body.zodSchema);
|
|
2245
|
-
config.update = {
|
|
2246
|
-
acl: getAclConfig(updateEndpoint, resolver.options),
|
|
2247
|
-
schema: require_generate_utils.getImportedZodSchemaName(resolver, body.zodSchema),
|
|
2248
|
-
mutation: updateEndpoint,
|
|
2249
|
-
inputDefs: getInputsConfig(resolver, body)
|
|
2250
|
-
};
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
const deleteEndpoint = extendedEndpoints.find((endpoint) => require_generate_utils.isDeleteEndpoint(endpoint, readAllEndpoint));
|
|
2254
|
-
if (deleteEndpoint) {
|
|
2255
|
-
importedEndpoints.push(deleteEndpoint);
|
|
2256
|
-
const body = require_generate_utils.getEndpointBody(deleteEndpoint);
|
|
2257
|
-
if (body) {
|
|
2258
|
-
importedZodSchemas.push(body.zodSchema);
|
|
2259
|
-
config.delete = {
|
|
2260
|
-
acl: getAclConfig(deleteEndpoint, resolver.options),
|
|
2261
|
-
mutation: deleteEndpoint
|
|
2262
|
-
};
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
const bulkDeleteEndpoint = extendedEndpoints.find((endpoint) => require_generate_utils.isBulkDeleteEndpoint(endpoint, readAllEndpoint));
|
|
2266
|
-
if (bulkDeleteEndpoint) {
|
|
2267
|
-
importedEndpoints.push(bulkDeleteEndpoint);
|
|
2268
|
-
const body = require_generate_utils.getEndpointBody(bulkDeleteEndpoint);
|
|
2269
|
-
if (body) {
|
|
2270
|
-
importedZodSchemas.push(body.zodSchema);
|
|
2271
|
-
config.bulkDelete = {
|
|
2272
|
-
acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
|
|
2273
|
-
schema: require_generate_utils.getImportedZodSchemaName(resolver, body.zodSchema),
|
|
2274
|
-
mutation: bulkDeleteEndpoint,
|
|
2275
|
-
inputDefs: getInputsConfig(resolver, body)
|
|
2276
|
-
};
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
return config;
|
|
2280
|
-
});
|
|
2281
|
-
const modelsImports = require_generate_utils.getModelsImports({
|
|
2282
|
-
resolver,
|
|
2283
|
-
tag,
|
|
2284
|
-
zodSchemas: importedZodSchemas
|
|
2285
|
-
});
|
|
2286
|
-
const queriesImports = require_generate_utils.getQueriesImports({
|
|
2287
|
-
tag,
|
|
2288
|
-
endpoints: importedEndpoints,
|
|
2289
|
-
options: resolver.options
|
|
2290
|
-
});
|
|
2291
|
-
const infiniteQueriesImports = resolver.options.infiniteQueries ? require_generate_utils.getInfiniteQueriesImports({
|
|
2292
|
-
tag,
|
|
2293
|
-
endpoints: importedInfiniteEndpoints,
|
|
2294
|
-
options: resolver.options
|
|
2295
|
-
}) : [];
|
|
2296
|
-
const aclImports = require_generate_utils.getAclImports({
|
|
2297
|
-
tag,
|
|
2298
|
-
endpoints: importedEndpoints.filter((endpoint) => endpoint.acl),
|
|
2299
|
-
options: resolver.options
|
|
2300
|
-
});
|
|
2301
|
-
return {
|
|
2302
|
-
configs: configs.filter(Boolean),
|
|
2303
|
-
hasZodImport,
|
|
2304
|
-
modelsImports,
|
|
2305
|
-
queriesImports: require_generate_utils.mergeImports(resolver.options, queriesImports, infiniteQueriesImports),
|
|
2306
|
-
aclImports
|
|
2307
|
-
};
|
|
2308
|
-
}
|
|
2309
|
-
function resolveBuilderConfigNames(endpoints) {
|
|
2310
|
-
const sortedEndpoints = endpoints.map((endpoint) => ({
|
|
2311
|
-
...endpoint,
|
|
2312
|
-
namePathSegments: endpoint.pathSegments.filter((segment) => !require_generate_utils.isPathSegmentParam(segment))
|
|
2313
|
-
})).toSorted((a, b) => a.namePathSegments.length - b.namePathSegments.length);
|
|
2314
|
-
const namedEndpoints = {};
|
|
2315
|
-
for (const endpoint of sortedEndpoints) {
|
|
2316
|
-
const namePathSegments = endpoint.namePathSegments;
|
|
2317
|
-
let name = namePathSegments.length > 0 ? `${require_generate_utils.kebabToCamel(namePathSegments.pop())}${require_generate_utils.capitalize(BUILD_CONFIG_SUFFIX)}` : BUILD_CONFIG_SUFFIX;
|
|
2318
|
-
while (namedEndpoints[name]) {
|
|
2319
|
-
if (namePathSegments.length === 0) throw new Error(`Can't uniquely resolve builder config name: ${name}`);
|
|
2320
|
-
name = `${require_generate_utils.kebabToCamel(namePathSegments.pop())}${require_generate_utils.capitalize(name)}`;
|
|
2321
|
-
}
|
|
2322
|
-
namedEndpoints[name] = endpoint;
|
|
2323
|
-
}
|
|
2324
|
-
return namedEndpoints;
|
|
2325
|
-
}
|
|
2326
|
-
function getAclConfig(endpoint, options) {
|
|
2327
|
-
return options.acl && endpoint.acl ? require_generate_utils.getImportedAbilityFunctionName(endpoint, options) : void 0;
|
|
2328
|
-
}
|
|
2329
|
-
function getInputsConfig(resolver, endpointParameter) {
|
|
2330
|
-
if (!endpointParameter) return;
|
|
2331
|
-
let schema;
|
|
2332
|
-
if (endpointParameter.type === "Body") schema = endpointParameter.bodyObject?.content?.[require_generate_utils.JSON_APPLICATION_FORMAT]?.schema;
|
|
2333
|
-
else schema = endpointParameter.parameterObject?.schema;
|
|
2334
|
-
if (!schema) return;
|
|
2335
|
-
const schemaObj = resolver.resolveObject(schema);
|
|
2336
|
-
const inputs = Object.keys(schemaObj?.properties ?? {}).reduce((acc, key) => ({
|
|
2337
|
-
...acc,
|
|
2338
|
-
[key]: true
|
|
2339
|
-
}), {});
|
|
2340
|
-
return {
|
|
2341
|
-
schema: require_generate_utils.getImportedZodSchemaName(resolver, endpointParameter.zodSchema),
|
|
2342
|
-
options: { inputs }
|
|
2343
|
-
};
|
|
2344
|
-
}
|
|
2345
|
-
function resolveReadAllItemZodSchema(resolver, endpoint, itemSchema, itemsPropertyKey) {
|
|
2346
|
-
if (require_generate_utils.isReferenceObject(itemSchema)) return resolver.getZodSchemaNameByRef(itemSchema.$ref);
|
|
2347
|
-
if (require_generate_utils.isNamedZodSchema(endpoint.response)) return `${require_generate_utils.getImportedZodSchemaName(resolver, endpoint.response)}.shape.${itemsPropertyKey}.element`;
|
|
2348
|
-
return require_generate_utils.ANY_SCHEMA;
|
|
2349
|
-
}
|
|
2350
|
-
function getColumnsConfig(resolver, endpoint) {
|
|
2351
|
-
const endpointResponse = endpoint.responseObject;
|
|
2352
|
-
if (!endpointResponse) return;
|
|
2353
|
-
const schema = endpointResponse.content?.[require_generate_utils.JSON_APPLICATION_FORMAT]?.schema;
|
|
2354
|
-
if (!schema) return;
|
|
2355
|
-
const properties = getSchemaProperties(resolver, schema);
|
|
2356
|
-
const arrayPropertyKeys = Object.keys(properties).filter((key) => resolver.resolveObject(properties[key]).type === "array");
|
|
2357
|
-
arrayPropertyKeys.sort((a, b) => {
|
|
2358
|
-
const aIndex = resolver.options.dataResponseParamNames.indexOf(a);
|
|
2359
|
-
const bIndex = resolver.options.dataResponseParamNames.indexOf(b);
|
|
2360
|
-
if (aIndex !== -1 && bIndex !== -1) return aIndex - bIndex;
|
|
2361
|
-
if (aIndex !== -1) return -1;
|
|
2362
|
-
if (bIndex !== -1) return 1;
|
|
2363
|
-
return a.localeCompare(b);
|
|
2364
|
-
});
|
|
2365
|
-
const propertyKey = arrayPropertyKeys[0];
|
|
2366
|
-
if (!propertyKey) return;
|
|
2367
|
-
const dataSchemaObj = resolver.resolveObject(properties[propertyKey]);
|
|
2368
|
-
if (!dataSchemaObj || dataSchemaObj.type !== "array") return;
|
|
2369
|
-
const itemSchema = dataSchemaObj.items;
|
|
2370
|
-
const itemSchemaObj = resolver.resolveObject(itemSchema);
|
|
2371
|
-
if (!itemSchemaObj) return;
|
|
2372
|
-
const zodSchema = resolveReadAllItemZodSchema(resolver, endpoint, itemSchema, propertyKey);
|
|
2373
|
-
const columns = Object.keys(itemSchemaObj?.properties ?? {}).reduce((acc, key) => ({
|
|
2374
|
-
...acc,
|
|
2375
|
-
[key]: true
|
|
2376
|
-
}), {});
|
|
2377
|
-
const sortableEnumSchemaName = endpoint.parameters.find((param) => param.parameterSortingEnumSchemaName)?.parameterSortingEnumSchemaName;
|
|
2378
|
-
return {
|
|
2379
|
-
columns: {
|
|
2380
|
-
schema: require_generate_utils.getImportedZodSchemaName(resolver, zodSchema),
|
|
2381
|
-
options: {
|
|
2382
|
-
columns,
|
|
2383
|
-
sortable: sortableEnumSchemaName ? require_generate_utils.getImportedZodSchemaName(resolver, sortableEnumSchemaName) : void 0
|
|
2384
|
-
}
|
|
2385
|
-
},
|
|
2386
|
-
zodSchema,
|
|
2387
|
-
sortableEnumSchemaName
|
|
2388
|
-
};
|
|
2389
|
-
}
|
|
2390
|
-
function getSchemaProperties(resolver, schema) {
|
|
2391
|
-
const schemaObj = resolver.resolveObject(schema);
|
|
2392
|
-
if (schemaObj.properties) return schemaObj.properties;
|
|
2393
|
-
else if ("allOf" in schemaObj && schemaObj.allOf) return schemaObj.allOf.reduce((acc, cur) => ({
|
|
2394
|
-
...acc,
|
|
2395
|
-
...getSchemaProperties(resolver, cur)
|
|
2396
|
-
}), {});
|
|
2397
|
-
return {};
|
|
2398
|
-
}
|
|
2399
|
-
//#endregion
|
|
2400
|
-
//#region src/generators/const/queries.const.ts
|
|
2401
|
-
const QUERY_HOOKS = {
|
|
2402
|
-
query: "useQuery",
|
|
2403
|
-
infiniteQuery: "useInfiniteQuery",
|
|
2404
|
-
mutation: "useMutation"
|
|
2405
|
-
};
|
|
2406
|
-
const QUERY_IMPORT = {
|
|
2407
|
-
bindings: [
|
|
2408
|
-
QUERY_HOOKS.query,
|
|
2409
|
-
QUERY_HOOKS.infiniteQuery,
|
|
2410
|
-
QUERY_HOOKS.mutation
|
|
2411
|
-
],
|
|
2412
|
-
from: "@tanstack/react-query"
|
|
2413
|
-
};
|
|
2414
|
-
const QUERIES_MODULE_NAME = "moduleName";
|
|
2415
|
-
//#endregion
|
|
2416
|
-
//#region src/generators/generate/generateConfigs.ts
|
|
2417
|
-
function generateConfigs(generateTypeParams) {
|
|
2418
|
-
const { configs, hasZodImport, modelsImports, queriesImports, aclImports } = getBuilderConfigs(generateTypeParams);
|
|
2419
|
-
if (configs.length === 0) return;
|
|
2420
|
-
const { resolver, tag } = generateTypeParams;
|
|
2421
|
-
const endpoints = configs.flatMap((config) => [
|
|
2422
|
-
config.create?.mutation,
|
|
2423
|
-
config.update?.mutation,
|
|
2424
|
-
config.delete?.mutation,
|
|
2425
|
-
config.bulkDelete?.mutation
|
|
2426
|
-
]).filter((m) => typeof m !== "string" && m !== void 0);
|
|
2427
|
-
const hasMutation = endpoints.length > 0;
|
|
2428
|
-
const hasAclCheck = resolver.options.checkAcl && endpoints.some((e) => e.acl);
|
|
2429
|
-
const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
|
|
2430
|
-
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
|
|
2431
|
-
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2432
|
-
const nativeClient = resolver.options.restClient === "native";
|
|
2433
|
-
const hasAxiosDefaultImport = !nativeClient && endpoints.some((e) => e.mediaUpload);
|
|
2434
|
-
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport);
|
|
2435
|
-
const axiosImport = {
|
|
2436
|
-
defaultImport: hasAxiosDefaultImport ? require_generate_utils.AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
2437
|
-
bindings: [],
|
|
2438
|
-
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2439
|
-
from: "axios"
|
|
2440
|
-
};
|
|
2441
|
-
const nativeImport = {
|
|
2442
|
-
bindings: [],
|
|
2443
|
-
typeBindings: nativeClient && hasAxiosRequestConfig ? [require_generate_utils.getRequestConfigTypeName("native")] : [],
|
|
2444
|
-
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2445
|
-
};
|
|
2446
|
-
const appRestClientImport = {
|
|
2447
|
-
bindings: [require_generate_utils.APP_REST_CLIENT_NAME],
|
|
2448
|
-
from: require_generate_utils.getAppRestClientImportPath(resolver.options)
|
|
2449
|
-
};
|
|
2450
|
-
const endpointsImports = require_generate_utils.getEndpointsImports({
|
|
2451
|
-
tag,
|
|
2452
|
-
endpoints,
|
|
2453
|
-
options: resolver.options
|
|
2454
|
-
});
|
|
2455
|
-
const queryImport = {
|
|
2456
|
-
bindings: [QUERY_HOOKS.mutation],
|
|
2457
|
-
from: "@tanstack/react-query"
|
|
2458
|
-
};
|
|
2459
|
-
const queryTypesImport = {
|
|
2460
|
-
bindings: [...hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
|
|
2461
|
-
typeBindings: [require_generate_utils.QUERY_OPTIONS_TYPES.mutation],
|
|
2462
|
-
from: require_generate_utils.getQueryTypesImportPath(resolver.options)
|
|
2463
|
-
};
|
|
2464
|
-
const mutationEffectsImport = {
|
|
2465
|
-
bindings: [require_generate_utils.MUTATION_EFFECTS.hookName],
|
|
2466
|
-
typeBindings: [require_generate_utils.MUTATION_EFFECTS.optionsType],
|
|
2467
|
-
from: resolver.options.mutationEffectsImportPath
|
|
2468
|
-
};
|
|
2469
|
-
const queryModulesImport = {
|
|
2470
|
-
bindings: [require_generate_utils.QUERY_MODULE_ENUM],
|
|
2471
|
-
from: require_generate_utils.getQueryModulesImportPath(resolver.options)
|
|
2472
|
-
};
|
|
2473
|
-
const aclCheckImport = {
|
|
2474
|
-
bindings: [ACL_CHECK_HOOK],
|
|
2475
|
-
from: resolver.options.aclCheckImportPath
|
|
2476
|
-
};
|
|
2477
|
-
const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
|
|
2478
|
-
const dynamicInputsImport = {
|
|
2479
|
-
bindings: [require_generate_utils.BUILDERS_UTILS.dynamicInputs],
|
|
2480
|
-
from: resolver.options.dynamicInputsImportPath
|
|
2481
|
-
};
|
|
2482
|
-
const hasDynamicColumnsImport = configs.some((config) => config.readAll.columns);
|
|
2483
|
-
const dynamicColumnsImport = {
|
|
2484
|
-
bindings: [require_generate_utils.BUILDERS_UTILS.dynamicColumns],
|
|
2485
|
-
from: resolver.options.dynamicColumnsImportPath
|
|
2486
|
-
};
|
|
2487
|
-
const lines = [];
|
|
2488
|
-
if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
|
|
2489
|
-
if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
|
|
2490
|
-
if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
|
|
2491
|
-
if (hasZodImport) lines.push(renderImport$3(require_generate_utils.ZOD_IMPORT));
|
|
2492
|
-
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
2493
|
-
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
2494
|
-
for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
|
|
2495
|
-
for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
|
|
2496
|
-
for (const endpointsImport of endpointsImports) lines.push(renderImport$3(endpointsImport));
|
|
2497
|
-
if (hasMutation) {
|
|
2498
|
-
lines.push(renderImport$3(queryImport));
|
|
2499
|
-
lines.push(renderImport$3(queryTypesImport));
|
|
2500
|
-
if (hasMutationEffects) {
|
|
2501
|
-
lines.push(renderImport$3(queryModulesImport));
|
|
2502
|
-
lines.push(renderImport$3(mutationEffectsImport));
|
|
2503
|
-
}
|
|
2504
|
-
if (hasAclCheck) lines.push(renderImport$3(aclCheckImport));
|
|
2505
|
-
}
|
|
2506
|
-
for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
|
|
2507
|
-
lines.push("");
|
|
2508
|
-
if (resolver.options.tsNamespaces) lines.push(`export namespace ${require_generate_utils.getNamespaceName({
|
|
2509
|
-
type: "configs",
|
|
2510
|
-
tag,
|
|
2511
|
-
options: resolver.options
|
|
2512
|
-
})} {`);
|
|
2513
|
-
for (const config of configs) {
|
|
2514
|
-
lines.push(renderBuilderConfig(config, generateTypeParams));
|
|
2515
|
-
lines.push("");
|
|
2516
|
-
}
|
|
2517
|
-
if (resolver.options.tsNamespaces) lines.push("}");
|
|
2518
|
-
return lines.join("\n").trimEnd() + "\n";
|
|
2519
|
-
}
|
|
2520
|
-
function renderImport$3(importData) {
|
|
2521
|
-
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
2522
|
-
const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
|
|
2523
|
-
return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
|
|
2524
|
-
}
|
|
2525
|
-
function renderInputsConfig(inputsConfig) {
|
|
2526
|
-
const lines = [];
|
|
2527
|
-
lines.push("{");
|
|
2528
|
-
lines.push(` schema: ${inputsConfig.schema},`);
|
|
2529
|
-
lines.push(" options: {");
|
|
2530
|
-
lines.push(" inputs: {");
|
|
2531
|
-
for (const key of Object.keys(inputsConfig.options.inputs)) lines.push(` ${key}: true,`);
|
|
2532
|
-
lines.push(" },");
|
|
2533
|
-
lines.push(" },");
|
|
2534
|
-
lines.push("}");
|
|
2535
|
-
return lines.join("\n");
|
|
2536
|
-
}
|
|
2537
|
-
function renderColumnsConfig(columnsConfig) {
|
|
2538
|
-
const lines = [];
|
|
2539
|
-
lines.push("{");
|
|
2540
|
-
lines.push(` schema: ${columnsConfig.schema},`);
|
|
2541
|
-
lines.push(" options: {");
|
|
2542
|
-
lines.push(" columns: {");
|
|
2543
|
-
for (const key of Object.keys(columnsConfig.options.columns)) lines.push(` ${key}: true,`);
|
|
2544
|
-
lines.push(" },");
|
|
2545
|
-
if (columnsConfig.options.sortable) lines.push(` sortable: ${columnsConfig.options.sortable},`);
|
|
2546
|
-
lines.push(" },");
|
|
2547
|
-
lines.push("}");
|
|
2548
|
-
return lines.join("\n");
|
|
2549
|
-
}
|
|
2550
|
-
function renderMutationContent(resolver, endpoint, tag) {
|
|
2551
|
-
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
2552
|
-
const hasMutationEffects = resolver.options.mutationEffects;
|
|
2553
|
-
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError;
|
|
2554
|
-
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2555
|
-
const endpointTag = require_generate_utils.getEndpointTag(endpoint, resolver.options);
|
|
2556
|
-
const endpointParams = require_generate_utils.mapEndpointParamsToFunctionParams(resolver, endpoint, {
|
|
2557
|
-
includeFileParam: true,
|
|
2558
|
-
modelNamespaceTag: endpointTag
|
|
2559
|
-
});
|
|
2560
|
-
const endpointParamsStr = endpointParams.map((p) => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ");
|
|
2561
|
-
const destructuredMutationArgs = endpointParams.map((p) => p.name).join(", ");
|
|
2562
|
-
const resolvedEndpointArgs = require_generate_utils.mapEndpointParamsToFunctionParams(resolver, endpoint, { modelNamespaceTag: endpointTag }).map((p) => p.name).join(", ");
|
|
2563
|
-
const endpointFunction = require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
2564
|
-
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
2565
|
-
const lines = [];
|
|
2566
|
-
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
2567
|
-
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
2568
|
-
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${require_generate_utils.QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${require_generate_utils.QUERY_MODULE_ENUM}.${tag} });`);
|
|
2569
|
-
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
2570
|
-
lines.push("");
|
|
2571
|
-
lines.push(` return ${QUERY_HOOKS.mutation}({`);
|
|
2572
|
-
const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
|
|
2573
|
-
lines.push(` mutationFn: ${endpoint.mediaUpload ? "async " : ""}(${mutationFnArg}) => {`);
|
|
2574
|
-
if (hasAclCheck) lines.push(require_generate_utils.renderAclCheckCall(resolver, endpoint, void 0, " "));
|
|
2575
|
-
if (endpoint.mediaUpload) lines.push(...require_generate_utils.renderMediaUploadMutationBody({
|
|
2576
|
-
resolver,
|
|
2577
|
-
endpointFunction,
|
|
2578
|
-
resolvedEndpointArgs
|
|
2579
|
-
}).map((line) => ` ${line}`));
|
|
2580
|
-
else lines.push(` return ${endpointFunction}(${destructuredMutationArgs}${hasAxiosRequestConfig ? `${destructuredMutationArgs ? ", " : ""}config` : ""});`);
|
|
2581
|
-
lines.push(" },");
|
|
2582
|
-
lines.push(" ...options,");
|
|
2583
|
-
if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
2584
|
-
if (hasMutationEffects) {
|
|
2585
|
-
lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
|
|
2586
|
-
lines.push(" await runMutationEffects(resData, variables, options);");
|
|
2587
|
-
lines.push(" options?.onSuccess?.(resData, variables, onMutateResult, context);");
|
|
2588
|
-
lines.push(" },");
|
|
2589
|
-
}
|
|
2590
|
-
lines.push(" });");
|
|
2591
|
-
lines.push("}");
|
|
2592
|
-
return lines.map((line) => " " + line).join("\n").trimStart();
|
|
2593
|
-
}
|
|
2594
|
-
function renderBuilderConfig(config, params) {
|
|
2595
|
-
const { resolver, tag } = params;
|
|
2596
|
-
const lines = [];
|
|
2597
|
-
lines.push(`export const ${config.name} = {`);
|
|
2598
|
-
lines.push(" meta: {");
|
|
2599
|
-
lines.push(` title: "${config.title}",`);
|
|
2600
|
-
lines.push(" },");
|
|
2601
|
-
lines.push(" readAll: {");
|
|
2602
|
-
if (config.readAll.acl) lines.push(` acl: ${config.readAll.acl},`);
|
|
2603
|
-
lines.push(` schema: ${config.readAll.columns.schema},`);
|
|
2604
|
-
lines.push(` paginated: ${config.readAll.paginated},`);
|
|
2605
|
-
if (config.readAll.infinite) lines.push(` infinite: ${config.readAll.infinite},`);
|
|
2606
|
-
if (config.readAll.filters) {
|
|
2607
|
-
lines.push(" filters: {");
|
|
2608
|
-
lines.push(` schema: ${config.readAll.filters.schema},`);
|
|
2609
|
-
lines.push(` filterDefs: ${require_generate_utils.BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.readAll.filters)})`);
|
|
2610
|
-
lines.push(" },");
|
|
2611
|
-
}
|
|
2612
|
-
lines.push(` columns: ${require_generate_utils.BUILDERS_UTILS.dynamicColumns}(${renderColumnsConfig(config.readAll.columns)}),`);
|
|
2613
|
-
lines.push(" },");
|
|
2614
|
-
if (config.read) {
|
|
2615
|
-
lines.push(" read: {");
|
|
2616
|
-
if (config.read.acl) lines.push(` acl: ${config.read.acl},`);
|
|
2617
|
-
lines.push(` schema: ${config.read.schema},`);
|
|
2618
|
-
lines.push(` query: ${config.read.query},`);
|
|
2619
|
-
lines.push(" },");
|
|
2620
|
-
}
|
|
2621
|
-
if (config.create) {
|
|
2622
|
-
lines.push(" create: {");
|
|
2623
|
-
if (config.create.acl) lines.push(` acl: ${config.create.acl},`);
|
|
2624
|
-
if (config.create.schema) lines.push(` schema: ${config.create.schema},`);
|
|
2625
|
-
lines.push(` mutation: ${typeof config.create.mutation === "string" ? config.create.mutation : renderMutationContent(resolver, config.create.mutation, tag)},`);
|
|
2626
|
-
if (config.create.inputDefs) lines.push(` inputDefs: ${require_generate_utils.BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.create.inputDefs)})`);
|
|
2627
|
-
lines.push(" },");
|
|
2628
|
-
}
|
|
2629
|
-
if (config.update) {
|
|
2630
|
-
lines.push(" update: {");
|
|
2631
|
-
if (config.update.acl) lines.push(` acl: ${config.update.acl},`);
|
|
2632
|
-
if (config.update.schema) lines.push(` schema: ${config.update.schema},`);
|
|
2633
|
-
lines.push(` mutation: ${typeof config.update.mutation === "string" ? config.update.mutation : renderMutationContent(resolver, config.update.mutation, tag)},`);
|
|
2634
|
-
if (config.update.inputDefs) lines.push(` inputDefs: ${require_generate_utils.BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.update.inputDefs)})`);
|
|
2635
|
-
lines.push(" },");
|
|
2636
|
-
}
|
|
2637
|
-
if (config.delete) {
|
|
2638
|
-
lines.push(" delete: {");
|
|
2639
|
-
if (config.delete.acl) lines.push(` acl: ${config.delete.acl},`);
|
|
2640
|
-
lines.push(` mutation: ${typeof config.delete.mutation === "string" ? config.delete.mutation : renderMutationContent(resolver, config.delete.mutation, tag)},`);
|
|
2641
|
-
lines.push(" },");
|
|
2642
|
-
}
|
|
2643
|
-
if (config.bulkDelete) {
|
|
2644
|
-
lines.push(" bulkDelete: {");
|
|
2645
|
-
if (config.bulkDelete.acl) lines.push(` acl: ${config.bulkDelete.acl},`);
|
|
2646
|
-
if (config.bulkDelete.schema) lines.push(` schema: ${config.bulkDelete.schema},`);
|
|
2647
|
-
lines.push(` mutation: ${typeof config.bulkDelete.mutation === "string" ? config.bulkDelete.mutation : renderMutationContent(resolver, config.bulkDelete.mutation, tag)},`);
|
|
2648
|
-
if (config.bulkDelete.inputDefs) lines.push(` inputDefs: ${require_generate_utils.BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.bulkDelete.inputDefs)})`);
|
|
2649
|
-
lines.push(" },");
|
|
2650
|
-
}
|
|
2651
|
-
lines.push("};");
|
|
2652
|
-
return lines.join("\n");
|
|
2653
|
-
}
|
|
2654
|
-
//#endregion
|
|
2655
2212
|
//#region src/generators/generate/generateEndpoints.ts
|
|
2656
2213
|
function generateEndpoints({ resolver, data, tag }) {
|
|
2657
2214
|
const nativeContent = resolver.getNativeRenderedEndpoints?.(tag);
|
|
@@ -2963,6 +2520,22 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
|
|
|
2963
2520
|
return lines.join("\n");
|
|
2964
2521
|
}
|
|
2965
2522
|
//#endregion
|
|
2523
|
+
//#region src/generators/const/queries.const.ts
|
|
2524
|
+
const QUERY_HOOKS = {
|
|
2525
|
+
query: "useQuery",
|
|
2526
|
+
infiniteQuery: "useInfiniteQuery",
|
|
2527
|
+
mutation: "useMutation"
|
|
2528
|
+
};
|
|
2529
|
+
const QUERY_IMPORT = {
|
|
2530
|
+
bindings: [
|
|
2531
|
+
QUERY_HOOKS.query,
|
|
2532
|
+
QUERY_HOOKS.infiniteQuery,
|
|
2533
|
+
QUERY_HOOKS.mutation
|
|
2534
|
+
],
|
|
2535
|
+
from: "@tanstack/react-query"
|
|
2536
|
+
};
|
|
2537
|
+
const QUERIES_MODULE_NAME = "moduleName";
|
|
2538
|
+
//#endregion
|
|
2966
2539
|
//#region src/generators/generate/generateQueries.ts
|
|
2967
2540
|
const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
|
|
2968
2541
|
const workspaceParamNamesCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -3294,9 +2867,9 @@ function addAsteriskAfterNewLine(str) {
|
|
|
3294
2867
|
}
|
|
3295
2868
|
function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
|
|
3296
2869
|
const lines = ["/** "];
|
|
3297
|
-
if (mode === "infiniteQuery") lines.push(` * Infinite query \`${
|
|
3298
|
-
else if (mode === "query") lines.push(` * Query \`${
|
|
3299
|
-
else lines.push(` * Mutation \`${
|
|
2870
|
+
if (mode === "infiniteQuery") lines.push(` * Infinite query \`${getInfiniteQueryName(endpoint)}${endpoint.summary ? "" : ""}`);
|
|
2871
|
+
else if (mode === "query") lines.push(` * Query \`${getQueryName(endpoint)}\`${endpoint.summary && endpoint.mediaDownload ? " - recommended when file should be cached" : ""}`);
|
|
2872
|
+
else lines.push(` * Mutation \`${getQueryName(endpoint, true)}\`${endpoint.summary && endpoint.mediaDownload ? " - recommended when file should not be cached" : ""}`);
|
|
3300
2873
|
if (endpoint.summary) lines.push(` * @summary ${addAsteriskAfterNewLine(endpoint.summary)}`);
|
|
3301
2874
|
if (endpoint.description) lines.push(` * @description ${addAsteriskAfterNewLine(endpoint.description)}`);
|
|
3302
2875
|
if (endpoint.acl) lines.push(` * @permission Requires \`${require_generate_utils.getAbilityFunctionName(endpoint)}\` ability `);
|
|
@@ -3328,7 +2901,7 @@ function renderQueryKeys({ resolver, queryEndpoints, tag }) {
|
|
|
3328
2901
|
pathParamsRequiredOnly: true,
|
|
3329
2902
|
modelNamespaceTag: tag
|
|
3330
2903
|
})}) => [...keys.all, "${endpoint.path}", ${renderEndpointArgs(resolver, endpoint, {})}] as const,`);
|
|
3331
|
-
if (resolver.options.infiniteQueries &&
|
|
2904
|
+
if (resolver.options.infiniteQueries && isInfiniteQuery(endpoint, resolver.options)) lines.push(` ${require_generate_utils.getEndpointName(endpoint)}Infinite: (${renderEndpointParams(resolver, endpoint, {
|
|
3332
2905
|
excludePageParam: true,
|
|
3333
2906
|
pathParamsRequiredOnly: true,
|
|
3334
2907
|
modelNamespaceTag: tag
|
|
@@ -3411,7 +2984,7 @@ function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3411
2984
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3412
2985
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3413
2986
|
const lines = [];
|
|
3414
|
-
lines.push(`const ${
|
|
2987
|
+
lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3415
2988
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}(${endpointArgs}),`);
|
|
3416
2989
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3417
2990
|
lines.push(` queryFn: ({ signal }: { signal: AbortSignal }) => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3428,7 +3001,7 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3428
3001
|
const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
3429
3002
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3430
3003
|
const lines = [];
|
|
3431
|
-
lines.push(`const ${
|
|
3004
|
+
lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3432
3005
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
|
|
3433
3006
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3434
3007
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3446,8 +3019,8 @@ function renderPrefetchQuery({ resolver, endpoint }) {
|
|
|
3446
3019
|
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: require_generate_utils.getEndpointTag(endpoint, resolver.options) });
|
|
3447
3020
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3448
3021
|
const lines = [];
|
|
3449
|
-
lines.push(`export const ${
|
|
3450
|
-
lines.push(` const queryOptions = { ...${
|
|
3022
|
+
lines.push(`export const ${getPrefetchQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchQuery"]>[0], "queryKey" | "queryFn">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
3023
|
+
lines.push(` const queryOptions = { ...${getQueryOptionsName(endpoint)}(${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}), ...options };`);
|
|
3451
3024
|
lines.push(` return throwOnError ? queryClient.fetchQuery(queryOptions) : queryClient.prefetchQuery(queryOptions);`);
|
|
3452
3025
|
lines.push("};");
|
|
3453
3026
|
return lines.join("\n");
|
|
@@ -3461,8 +3034,8 @@ function renderPrefetchInfiniteQuery({ resolver, endpoint }) {
|
|
|
3461
3034
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
3462
3035
|
const optionsArgs = `${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
3463
3036
|
const lines = [];
|
|
3464
|
-
lines.push(`export const ${
|
|
3465
|
-
lines.push(` const queryOptions = { ...${
|
|
3037
|
+
lines.push(`export const ${getPrefetchInfiniteQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchInfiniteQuery"]>[0], "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
3038
|
+
lines.push(` const queryOptions = { ...${getInfiniteQueryOptionsName(endpoint)}(${optionsArgs}), ...(options as {}) };`);
|
|
3466
3039
|
lines.push(` return throwOnError ? queryClient.fetchInfiniteQuery(queryOptions) : queryClient.prefetchInfiniteQuery(queryOptions);`);
|
|
3467
3040
|
lines.push("};");
|
|
3468
3041
|
return lines.join("\n");
|
|
@@ -3479,7 +3052,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3479
3052
|
optionalPathParams: resolver.options.workspaceContext,
|
|
3480
3053
|
modelNamespaceTag: tag
|
|
3481
3054
|
});
|
|
3482
|
-
const queryOptionsName =
|
|
3055
|
+
const queryOptionsName = getQueryOptionsName(endpoint);
|
|
3483
3056
|
const hasQueryFnOverride = hasAclCheck;
|
|
3484
3057
|
const requestConfig = `{ ${hasAxiosRequestConfig ? `...${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}, ` : ""}allowInvalidResponseData: queryConfig.allowInvalidResponseData }`;
|
|
3485
3058
|
const queryOptionsArgs = `${resolvedEndpointArgs ? `{ ${resolvedEndpointArgs} }, ` : ""}${requestConfig}`;
|
|
@@ -3490,7 +3063,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3490
3063
|
mode: "query",
|
|
3491
3064
|
tag
|
|
3492
3065
|
}));
|
|
3493
|
-
lines.push(`export const ${
|
|
3066
|
+
lines.push(`export const ${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)}` : ""}) => {`);
|
|
3494
3067
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3495
3068
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3496
3069
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3529,7 +3102,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
3529
3102
|
const destructuredMutationArgs = renderEndpointArgs(resolver, endpoint, { includeFileParam: true });
|
|
3530
3103
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3531
3104
|
const updateQueryEndpoints = precomputed?.updateQueryEndpoints ?? [];
|
|
3532
|
-
const destructuredVariables = precomputed?.destructuredVariables ??
|
|
3105
|
+
const destructuredVariables = precomputed?.destructuredVariables ?? getDestructuredVariables(resolver, endpoint, updateQueryEndpoints);
|
|
3533
3106
|
const hasMutationFnBody = endpoint.mediaUpload || hasAclCheck || Object.keys(workspaceParamReplacements).length > 0;
|
|
3534
3107
|
const mutationVariablesType = endpoint.mediaUpload ? `${endpointParams}${endpointParams ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void` : endpointParams;
|
|
3535
3108
|
const isPost = endpoint.method === "post";
|
|
@@ -3560,7 +3133,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
3560
3133
|
mode: "mutation",
|
|
3561
3134
|
tag
|
|
3562
3135
|
}));
|
|
3563
|
-
lines.push(`export const ${
|
|
3136
|
+
lines.push(`export const ${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)}` : ""}) => {`);
|
|
3564
3137
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3565
3138
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3566
3139
|
lines.push(...renderWorkspaceContextDestructure({
|
|
@@ -3626,9 +3199,9 @@ function groupEndpoints(endpoints, resolver) {
|
|
|
3626
3199
|
const infoByEndpoint = /* @__PURE__ */ new Map();
|
|
3627
3200
|
const mutationDataByEndpoint = /* @__PURE__ */ new Map();
|
|
3628
3201
|
for (const endpoint of endpoints) {
|
|
3629
|
-
const query =
|
|
3630
|
-
const mutation =
|
|
3631
|
-
const infiniteQuery = Boolean(resolver.options.infiniteQueries && query &&
|
|
3202
|
+
const query = isQuery(endpoint);
|
|
3203
|
+
const mutation = isMutation(endpoint);
|
|
3204
|
+
const infiniteQuery = Boolean(resolver.options.infiniteQueries && query && isInfiniteQuery(endpoint, resolver.options));
|
|
3632
3205
|
if (query) queryEndpoints.push(endpoint);
|
|
3633
3206
|
if (mutation) mutationEndpoints.push(endpoint);
|
|
3634
3207
|
if (infiniteQuery) infiniteQueryEndpoints.push(endpoint);
|
|
@@ -3643,7 +3216,7 @@ function groupEndpoints(endpoints, resolver) {
|
|
|
3643
3216
|
const updateQueryEndpoints = queryEndpoints.filter((queryEndpoint) => queryEndpoint.parameters.filter((param) => param.parameterObject?.required).every((pathParam) => endpoint.parameters.some((param) => param.name === pathParam.name)) && queryEndpoint.response === endpoint.response);
|
|
3644
3217
|
mutationDataByEndpoint.set(endpoint, {
|
|
3645
3218
|
updateQueryEndpoints,
|
|
3646
|
-
destructuredVariables:
|
|
3219
|
+
destructuredVariables: getDestructuredVariables(resolver, endpoint, updateQueryEndpoints)
|
|
3647
3220
|
});
|
|
3648
3221
|
}
|
|
3649
3222
|
return {
|
|
@@ -3668,7 +3241,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3668
3241
|
});
|
|
3669
3242
|
const endpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
3670
3243
|
const resolvedEndpointArgsWithoutPage = renderEndpointObjectArgs(resolver, endpoint, { excludePageParam: true }, workspaceParamReplacements);
|
|
3671
|
-
const queryOptionsName =
|
|
3244
|
+
const queryOptionsName = getInfiniteQueryOptionsName(endpoint);
|
|
3672
3245
|
const requestConfig = `{ ${hasAxiosRequestConfig ? `...${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}, ` : ""}allowInvalidResponseData: queryConfig.allowInvalidResponseData }`;
|
|
3673
3246
|
const queryOptionsArgs = `${resolvedEndpointArgsWithoutPage ? `{ ${resolvedEndpointArgsWithoutPage} }, ` : ""}${requestConfig}`;
|
|
3674
3247
|
const hasQueryFnOverride = hasAclCheck;
|
|
@@ -3679,7 +3252,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3679
3252
|
mode: "infiniteQuery",
|
|
3680
3253
|
tag
|
|
3681
3254
|
}));
|
|
3682
|
-
lines.push(`export const ${
|
|
3255
|
+
lines.push(`export const ${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)}` : ""}) => {`);
|
|
3683
3256
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3684
3257
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3685
3258
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3771,7 +3344,7 @@ function generateQueryModules({ resolver, data }) {
|
|
|
3771
3344
|
tag,
|
|
3772
3345
|
options: resolver.options
|
|
3773
3346
|
}),
|
|
3774
|
-
mutationHooks: endpoints.filter(
|
|
3347
|
+
mutationHooks: endpoints.filter(isMutation).map((endpoint) => getQueryName(endpoint, true))
|
|
3775
3348
|
});
|
|
3776
3349
|
});
|
|
3777
3350
|
const mutationModules = modules.filter((module) => module.mutationHooks.length > 0);
|
|
@@ -3800,6 +3373,7 @@ function generateQueryModules({ resolver, data }) {
|
|
|
3800
3373
|
lines.push("}");
|
|
3801
3374
|
lines.push("");
|
|
3802
3375
|
lines.push("declare global {");
|
|
3376
|
+
lines.push(" interface OpenApiCodegenQueryModules { queryModule: QueryModule }");
|
|
3803
3377
|
lines.push(" interface OpenApiCodegenQueryModuleMutations extends QueryModuleMutations {}");
|
|
3804
3378
|
lines.push("}");
|
|
3805
3379
|
return lines.join("\n");
|
|
@@ -4067,15 +3641,13 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler, nativeSource)
|
|
|
4067
3641
|
"models",
|
|
4068
3642
|
...shouldGenerateEndpoints ? ["endpoints"] : [],
|
|
4069
3643
|
"queries",
|
|
4070
|
-
...resolver.options.acl ? ["acl"] : []
|
|
4071
|
-
...resolver.options.builderConfigs ? ["configs"] : []
|
|
3644
|
+
...resolver.options.acl ? ["acl"] : []
|
|
4072
3645
|
];
|
|
4073
3646
|
const generateFunctions = {
|
|
4074
3647
|
["models"]: generateModels,
|
|
4075
3648
|
["endpoints"]: generateEndpoints,
|
|
4076
3649
|
["queries"]: generateQueries,
|
|
4077
|
-
["acl"]: generateAcl
|
|
4078
|
-
["configs"]: generateConfigs
|
|
3650
|
+
["acl"]: generateAcl
|
|
4079
3651
|
};
|
|
4080
3652
|
data.forEach((_, tag) => {
|
|
4081
3653
|
generateTypes.forEach((type) => {
|