@povio/openapi-codegen-cli 4.0.0-rc.3 → 4.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +38 -11
  2. package/dist/{config-CiLFKLAY.d.mts → config-D8ANLlqk.d.mts} +1 -1
  3. package/dist/config.d.mts +2 -2
  4. package/dist/{generate.runner-Sh0Ps6AW.mjs → generate.runner-LDL6Lbgl.mjs} +8 -110
  5. package/dist/{generate.utils-BJxdEik8.cjs → generate.utils-BFeGvk98.cjs} +4 -269
  6. package/dist/{generateCodeFromOpenAPIDoc-B8FAsxWE.mjs → generateCodeFromOpenAPIDoc-B7VWwIbb.mjs} +198 -502
  7. package/dist/{generateCodeFromOpenAPIDoc-Bbi8fYi2.cjs → generateCodeFromOpenAPIDoc-CpAdx6I3.cjs} +241 -528
  8. package/dist/generator.d.mts +1 -1
  9. package/dist/generator.mjs +3 -3
  10. package/dist/{getDataFromOpenAPIDoc-CXYNMMMt.mjs → getDataFromOpenAPIDoc-C0iehdg8.mjs} +19 -2
  11. package/dist/index.d.mts +4 -4
  12. package/dist/metro.cjs +4 -3
  13. package/dist/metro.d.mts +3 -3
  14. package/dist/metro.mjs +1 -1
  15. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  16. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  17. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  18. package/dist/{openapi-codegen.runner-bJTFHTdn.mjs → openapi-codegen.runner-CmW9oZdT.mjs} +1 -1
  19. package/dist/{openapi-source.runner-DIOvAX_R.d.mts → openapi-source.runner-DES1kzvS.d.mts} +1 -1
  20. package/dist/{options-X0zju7gw.d.mts → options-B7-eMFcv.d.mts} +4 -10
  21. package/dist/query.d.mts +3 -3
  22. package/dist/queryConfig.context-DwVQWbtL.d.mts +71 -0
  23. package/dist/sh.mjs +8 -8
  24. package/dist/tiny.d.mts +1 -1
  25. package/dist/{useMutationEffects-CJJuL9Ak.d.mts → useMutationEffects-I4y5WUkj.d.mts} +1 -1
  26. package/dist/vite.d.mts +3 -3
  27. package/dist/vite.mjs +1 -1
  28. package/package.json +4 -4
  29. package/dist/queryConfig.context-DjhzewdL.d.mts +0 -56
@@ -1,5 +1,5 @@
1
- import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-CXYNMMMt.mjs";
2
- import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as NATIVE_RESPONSE_TYPE, At as APP_REST_CLIENT_NAME, B as getPrefetchInfiniteQueryName, Bt as NATIVE_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 AXIOS_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 CONFIG_PACKAGE_IMPORT_PATH } from "./generate.runner-Sh0Ps6AW.mjs";
1
+ import { a as isQuery, i as isMutation, n as getDestructuredVariables, r as isInfiniteQuery, s as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-C0iehdg8.mjs";
2
+ import { $t as AXIOS_DEFAULT_IMPORT_NAME, A as getAbilityConditionType, B as getImportedZodSchemaInferedTypeName, C as getTagFileName, D as getImportPath, E as getEndpointsImports, Et as isParamMediaTypeAllowed, F as getAbilitySubjectTypes, G as getZodSchemaType, H as getZodSchemaDescription, I as getAclData, J as getUniqueArray, K as getSchemaDescriptions, L as getAppAbilitiesType, Lt as isReferenceObject, M as getAbilityDescription, N as getAbilityFunctionName, O as getModelsImports, P as getAbilitySubject, Pt as wrapWithQuotesIfNeeded, Qt as ZOD_IMPORT, R as hasAbilityConditions, Rt as isSchemaObject, S as getQueryTypesImportPath, T as getAclImports, U as getZodSchemaInferedTypeName, V as getImportedZodSchemaName, W as getZodSchemaPropertyDescriptions, X as invalidVariableNameCharactersToCamel, Y as DEFAULT_GENERATE_OPTIONS, _n as Profiler, _t as getNamespaceName, an as NATIVE_RESPONSE_TYPE, at as APP_REST_CLIENT_FILE, b as getFileNameWithExtension, c as getEndpointBody, cn as getEndpointTag, ct as MUTATION_EFFECTS, d as getEndpointPath, dn as shouldInlineEndpointsForTag, dt as QUERY_OPTIONS_TYPES, en as AXIOS_IMPORT, f as getImportedEndpointName, fn as capitalize, ft as ZOD_EXTENDED, g as requiresBody, gn as snakeToCamel, gt as REST_PACKAGE_IMPORT_PATH, h as renderMediaUploadMutationBody, ht as NATIVE_PACKAGE_IMPORT_PATH, i as shouldUseNativeCodegen, it as isNamedZodSchema, j as getAbilityConditionsTypes, k as getAbilityAction, l as getEndpointConfig, lt as QUERY_MODULES_FILE, m as mapEndpointParamsToFunctionParams, mt as CONFIG_PACKAGE_IMPORT_PATH, nn as AXIOS_REQUEST_CONFIG_TYPE, o as getOutputFileName, on as getRequestConfigTypeName, ot as APP_REST_CLIENT_NAME, p as hasEndpointConfig, pt as AXIOS_PACKAGE_IMPORT_PATH, r as compileNativeData, rt as isEnumZodSchema, st as DOMAIN_ERRORS_FILE, tn as AXIOS_REQUEST_CONFIG_NAME, u as getEndpointName, ut as QUERY_MODULE_ENUM, w as getTagImportPath, x as getQueryModulesImportPath, y as getAppRestClientImportPath, z as renderAclCheckCall } from "./generate.runner-LDL6Lbgl.mjs";
3
3
  import "node:module";
4
4
  //#region \0rolldown/runtime.js
5
5
  var __defProp = Object.defineProperty;
@@ -38,6 +38,35 @@ const CASL_ABILITY_IMPORT = {
38
38
  from: "@casl/ability"
39
39
  };
40
40
  //#endregion
41
+ //#region src/generators/utils/generate/generate.query.utils.ts
42
+ const operationNameByEndpoint = /* @__PURE__ */ new WeakMap();
43
+ const capitalizedOperationNameByEndpoint = /* @__PURE__ */ new WeakMap();
44
+ function getOperationName(endpoint) {
45
+ let name = operationNameByEndpoint.get(endpoint);
46
+ if (name === void 0) {
47
+ name = snakeToCamel(endpoint.operationName);
48
+ operationNameByEndpoint.set(endpoint, name);
49
+ }
50
+ return name;
51
+ }
52
+ function getCapitalizedOperationName(endpoint) {
53
+ let name = capitalizedOperationNameByEndpoint.get(endpoint);
54
+ if (name === void 0) {
55
+ name = capitalize(getOperationName(endpoint));
56
+ capitalizedOperationNameByEndpoint.set(endpoint, name);
57
+ }
58
+ return name;
59
+ }
60
+ const getQueryName = (endpoint, mutation) => {
61
+ const addMutationSuffix = isQuery(endpoint) && isMutation(endpoint) && mutation;
62
+ return `use${getCapitalizedOperationName(endpoint)}${addMutationSuffix ? "Mutation" : ""}`;
63
+ };
64
+ const getInfiniteQueryName = (endpoint) => `use${getCapitalizedOperationName(endpoint)}Infinite`;
65
+ const getQueryOptionsName = (endpoint) => `${getOperationName(endpoint)}QueryOptions`;
66
+ const getInfiniteQueryOptionsName = (endpoint) => `${getOperationName(endpoint)}InfiniteQueryOptions`;
67
+ const getPrefetchQueryName = (endpoint) => `prefetch${getCapitalizedOperationName(endpoint)}`;
68
+ const getPrefetchInfiniteQueryName = (endpoint) => `prefetch${getCapitalizedOperationName(endpoint)}Infinite`;
69
+ //#endregion
41
70
  //#region src/generators/generate/generateAcl.ts
42
71
  function generateAcl({ resolver, data, tag }) {
43
72
  const nativeContent = resolver.getNativeRenderedAcl?.(tag);
@@ -60,9 +89,9 @@ function generateAcl({ resolver, data, tag }) {
60
89
  from: CONFIG_PACKAGE_IMPORT_PATH
61
90
  };
62
91
  const lines = [];
63
- lines.push(renderImport$4(caslAbilityTupleImport));
64
- if (hasWorkspaceContext) lines.push(renderImport$4(workspaceContextImport));
65
- for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
92
+ lines.push(renderImport$3(caslAbilityTupleImport));
93
+ if (hasWorkspaceContext) lines.push(renderImport$3(workspaceContextImport));
94
+ for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
66
95
  lines.push("");
67
96
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
68
97
  type: "acl",
@@ -98,8 +127,8 @@ function generateAppAcl({ resolver, data }) {
98
127
  typeOnly: true
99
128
  };
100
129
  const lines = [];
101
- lines.push(renderImport$4(caslAbilityTupleImport));
102
- for (const modelsImport of modelsImports) lines.push(renderImport$4(modelsImport));
130
+ lines.push(renderImport$3(caslAbilityTupleImport));
131
+ for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
103
132
  lines.push("");
104
133
  if (appAbilitiesType) {
105
134
  lines.push(`export type ${ACL_APP_ABILITIES} = `);
@@ -109,7 +138,7 @@ function generateAppAcl({ resolver, data }) {
109
138
  lines.push(`export type AppAbility = PureAbility<${ACL_APP_ABILITIES}>;`);
110
139
  return lines.join("\n");
111
140
  }
112
- function renderImport$4(importData) {
141
+ function renderImport$3(importData) {
113
142
  const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
114
143
  const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
115
144
  return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
@@ -180,495 +209,6 @@ function renderConditionType(resolver, endpoint, propertyType) {
180
209
  return getAbilityConditionType(propertyType, resolver, getEndpointTag(endpoint, resolver.options));
181
210
  }
182
211
  //#endregion
183
- //#region src/generators/const/buildConfigs.const.ts
184
- const BUILD_CONFIG_SUFFIX = "config";
185
- //#endregion
186
- //#region src/generators/utils/generate/generate.configs.utils.ts
187
- function getBuilderConfigs({ data, tag, resolver }) {
188
- const endpoints = data.get(tag)?.endpoints;
189
- if (!endpoints || endpoints.length === 0) return {
190
- configs: [],
191
- hasZodImport: false,
192
- modelsImports: [],
193
- queriesImports: [],
194
- aclImports: []
195
- };
196
- const extendedEndpoints = endpoints.map((endpoint) => ({
197
- ...endpoint,
198
- pathSegments: getPathSegments(endpoint.path)
199
- }));
200
- const namedReadAllEndpoints = resolveBuilderConfigNames(extendedEndpoints.filter((endpoint) => isReadAllEndpoint(endpoint, resolver.options)));
201
- let hasZodImport = false;
202
- const importedZodSchemas = [];
203
- const importedEndpoints = [];
204
- const importedInfiniteEndpoints = [];
205
- const configs = Object.entries(namedReadAllEndpoints).map(([name, readAllEndpoint]) => {
206
- const columnsConfig = getColumnsConfig(resolver, readAllEndpoint);
207
- if (!columnsConfig) return;
208
- importedEndpoints.push(readAllEndpoint);
209
- importedInfiniteEndpoints.push(readAllEndpoint);
210
- if (columnsConfig.zodSchema) {
211
- if (isNamedZodSchema(columnsConfig.zodSchema)) importedZodSchemas.push(columnsConfig.zodSchema);
212
- else hasZodImport = true;
213
- }
214
- if (columnsConfig.sortableEnumSchemaName) importedZodSchemas.push(columnsConfig.sortableEnumSchemaName);
215
- const filter = readAllEndpoint.parameters.find((param) => param.name === resolver.options.filterParamName);
216
- if (filter) importedZodSchemas.push(filter.zodSchema);
217
- const config = {
218
- name,
219
- title: capitalize(camelToSpaceSeparated(name.replace(/config$/i, ""))),
220
- readAll: {
221
- acl: getAclConfig(readAllEndpoint, resolver.options),
222
- paginated: getImportedQueryName(readAllEndpoint, resolver.options),
223
- infinite: resolver.options.infiniteQueries ? getImportedInfiniteQueryName(readAllEndpoint, resolver.options) : void 0,
224
- filters: getInputsConfig(resolver, filter),
225
- columns: columnsConfig.columns
226
- }
227
- };
228
- const readEndpoint = extendedEndpoints.find((endpoint) => isReadEndpoint(endpoint, readAllEndpoint));
229
- if (readEndpoint) {
230
- importedEndpoints.push(readEndpoint);
231
- let responseSchema = readEndpoint.response;
232
- if (isNamedZodSchema(responseSchema)) {
233
- importedZodSchemas.push(responseSchema);
234
- responseSchema = getImportedZodSchemaName(resolver, responseSchema);
235
- } else hasZodImport = true;
236
- config.read = {
237
- acl: getAclConfig(readEndpoint, resolver.options),
238
- schema: responseSchema,
239
- query: getImportedQueryName(readEndpoint, resolver.options)
240
- };
241
- }
242
- const createEndpoint = extendedEndpoints.find((endpoint) => isCreateEndpoint(endpoint, readAllEndpoint));
243
- if (createEndpoint) {
244
- importedEndpoints.push(createEndpoint);
245
- const body = getEndpointBody(createEndpoint);
246
- if (body) {
247
- importedZodSchemas.push(body.zodSchema);
248
- config.create = {
249
- acl: getAclConfig(createEndpoint, resolver.options),
250
- schema: getImportedZodSchemaName(resolver, body.zodSchema),
251
- mutation: createEndpoint,
252
- inputDefs: getInputsConfig(resolver, body)
253
- };
254
- }
255
- }
256
- const updateEndpoint = extendedEndpoints.find((endpoint) => isUpdateEndpoint(endpoint, readAllEndpoint));
257
- if (updateEndpoint) {
258
- importedEndpoints.push(updateEndpoint);
259
- const body = getEndpointBody(updateEndpoint);
260
- if (body) {
261
- importedZodSchemas.push(body.zodSchema);
262
- config.update = {
263
- acl: getAclConfig(updateEndpoint, resolver.options),
264
- schema: getImportedZodSchemaName(resolver, body.zodSchema),
265
- mutation: updateEndpoint,
266
- inputDefs: getInputsConfig(resolver, body)
267
- };
268
- }
269
- }
270
- const deleteEndpoint = extendedEndpoints.find((endpoint) => isDeleteEndpoint(endpoint, readAllEndpoint));
271
- if (deleteEndpoint) {
272
- importedEndpoints.push(deleteEndpoint);
273
- const body = getEndpointBody(deleteEndpoint);
274
- if (body) {
275
- importedZodSchemas.push(body.zodSchema);
276
- config.delete = {
277
- acl: getAclConfig(deleteEndpoint, resolver.options),
278
- mutation: deleteEndpoint
279
- };
280
- }
281
- }
282
- const bulkDeleteEndpoint = extendedEndpoints.find((endpoint) => isBulkDeleteEndpoint(endpoint, readAllEndpoint));
283
- if (bulkDeleteEndpoint) {
284
- importedEndpoints.push(bulkDeleteEndpoint);
285
- const body = getEndpointBody(bulkDeleteEndpoint);
286
- if (body) {
287
- importedZodSchemas.push(body.zodSchema);
288
- config.bulkDelete = {
289
- acl: getAclConfig(bulkDeleteEndpoint, resolver.options),
290
- schema: getImportedZodSchemaName(resolver, body.zodSchema),
291
- mutation: bulkDeleteEndpoint,
292
- inputDefs: getInputsConfig(resolver, body)
293
- };
294
- }
295
- }
296
- return config;
297
- });
298
- const modelsImports = getModelsImports({
299
- resolver,
300
- tag,
301
- zodSchemas: importedZodSchemas
302
- });
303
- const queriesImports = getQueriesImports({
304
- tag,
305
- endpoints: importedEndpoints,
306
- options: resolver.options
307
- });
308
- const infiniteQueriesImports = resolver.options.infiniteQueries ? getInfiniteQueriesImports({
309
- tag,
310
- endpoints: importedInfiniteEndpoints,
311
- options: resolver.options
312
- }) : [];
313
- const aclImports = getAclImports({
314
- tag,
315
- endpoints: importedEndpoints.filter((endpoint) => endpoint.acl),
316
- options: resolver.options
317
- });
318
- return {
319
- configs: configs.filter(Boolean),
320
- hasZodImport,
321
- modelsImports,
322
- queriesImports: mergeImports(resolver.options, queriesImports, infiniteQueriesImports),
323
- aclImports
324
- };
325
- }
326
- function resolveBuilderConfigNames(endpoints) {
327
- const sortedEndpoints = endpoints.map((endpoint) => ({
328
- ...endpoint,
329
- namePathSegments: endpoint.pathSegments.filter((segment) => !isPathSegmentParam(segment))
330
- })).toSorted((a, b) => a.namePathSegments.length - b.namePathSegments.length);
331
- const namedEndpoints = {};
332
- for (const endpoint of sortedEndpoints) {
333
- const namePathSegments = endpoint.namePathSegments;
334
- let name = namePathSegments.length > 0 ? `${kebabToCamel(namePathSegments.pop())}${capitalize(BUILD_CONFIG_SUFFIX)}` : BUILD_CONFIG_SUFFIX;
335
- while (namedEndpoints[name]) {
336
- if (namePathSegments.length === 0) throw new Error(`Can't uniquely resolve builder config name: ${name}`);
337
- name = `${kebabToCamel(namePathSegments.pop())}${capitalize(name)}`;
338
- }
339
- namedEndpoints[name] = endpoint;
340
- }
341
- return namedEndpoints;
342
- }
343
- function getAclConfig(endpoint, options) {
344
- return options.acl && endpoint.acl ? getImportedAbilityFunctionName(endpoint, options) : void 0;
345
- }
346
- function getInputsConfig(resolver, endpointParameter) {
347
- if (!endpointParameter) return;
348
- let schema;
349
- if (endpointParameter.type === "Body") schema = endpointParameter.bodyObject?.content?.[JSON_APPLICATION_FORMAT]?.schema;
350
- else schema = endpointParameter.parameterObject?.schema;
351
- if (!schema) return;
352
- const schemaObj = resolver.resolveObject(schema);
353
- const inputs = Object.keys(schemaObj?.properties ?? {}).reduce((acc, key) => ({
354
- ...acc,
355
- [key]: true
356
- }), {});
357
- return {
358
- schema: getImportedZodSchemaName(resolver, endpointParameter.zodSchema),
359
- options: { inputs }
360
- };
361
- }
362
- function resolveReadAllItemZodSchema(resolver, endpoint, itemSchema, itemsPropertyKey) {
363
- if (isReferenceObject(itemSchema)) return resolver.getZodSchemaNameByRef(itemSchema.$ref);
364
- if (isNamedZodSchema(endpoint.response)) return `${getImportedZodSchemaName(resolver, endpoint.response)}.shape.${itemsPropertyKey}.element`;
365
- return ANY_SCHEMA;
366
- }
367
- function getColumnsConfig(resolver, endpoint) {
368
- const endpointResponse = endpoint.responseObject;
369
- if (!endpointResponse) return;
370
- const schema = endpointResponse.content?.[JSON_APPLICATION_FORMAT]?.schema;
371
- if (!schema) return;
372
- const properties = getSchemaProperties(resolver, schema);
373
- const arrayPropertyKeys = Object.keys(properties).filter((key) => resolver.resolveObject(properties[key]).type === "array");
374
- arrayPropertyKeys.sort((a, b) => {
375
- const aIndex = resolver.options.dataResponseParamNames.indexOf(a);
376
- const bIndex = resolver.options.dataResponseParamNames.indexOf(b);
377
- if (aIndex !== -1 && bIndex !== -1) return aIndex - bIndex;
378
- if (aIndex !== -1) return -1;
379
- if (bIndex !== -1) return 1;
380
- return a.localeCompare(b);
381
- });
382
- const propertyKey = arrayPropertyKeys[0];
383
- if (!propertyKey) return;
384
- const dataSchemaObj = resolver.resolveObject(properties[propertyKey]);
385
- if (!dataSchemaObj || dataSchemaObj.type !== "array") return;
386
- const itemSchema = dataSchemaObj.items;
387
- const itemSchemaObj = resolver.resolveObject(itemSchema);
388
- if (!itemSchemaObj) return;
389
- const zodSchema = resolveReadAllItemZodSchema(resolver, endpoint, itemSchema, propertyKey);
390
- const columns = Object.keys(itemSchemaObj?.properties ?? {}).reduce((acc, key) => ({
391
- ...acc,
392
- [key]: true
393
- }), {});
394
- const sortableEnumSchemaName = endpoint.parameters.find((param) => param.parameterSortingEnumSchemaName)?.parameterSortingEnumSchemaName;
395
- return {
396
- columns: {
397
- schema: getImportedZodSchemaName(resolver, zodSchema),
398
- options: {
399
- columns,
400
- sortable: sortableEnumSchemaName ? getImportedZodSchemaName(resolver, sortableEnumSchemaName) : void 0
401
- }
402
- },
403
- zodSchema,
404
- sortableEnumSchemaName
405
- };
406
- }
407
- function getSchemaProperties(resolver, schema) {
408
- const schemaObj = resolver.resolveObject(schema);
409
- if (schemaObj.properties) return schemaObj.properties;
410
- else if ("allOf" in schemaObj && schemaObj.allOf) return schemaObj.allOf.reduce((acc, cur) => ({
411
- ...acc,
412
- ...getSchemaProperties(resolver, cur)
413
- }), {});
414
- return {};
415
- }
416
- //#endregion
417
- //#region src/generators/const/queries.const.ts
418
- const QUERY_HOOKS = {
419
- query: "useQuery",
420
- infiniteQuery: "useInfiniteQuery",
421
- mutation: "useMutation"
422
- };
423
- const QUERY_IMPORT = {
424
- bindings: [
425
- QUERY_HOOKS.query,
426
- QUERY_HOOKS.infiniteQuery,
427
- QUERY_HOOKS.mutation
428
- ],
429
- from: "@tanstack/react-query"
430
- };
431
- const QUERIES_MODULE_NAME = "moduleName";
432
- //#endregion
433
- //#region src/generators/generate/generateConfigs.ts
434
- function generateConfigs(generateTypeParams) {
435
- const { configs, hasZodImport, modelsImports, queriesImports, aclImports } = getBuilderConfigs(generateTypeParams);
436
- if (configs.length === 0) return;
437
- const { resolver, tag } = generateTypeParams;
438
- const endpoints = configs.flatMap((config) => [
439
- config.create?.mutation,
440
- config.update?.mutation,
441
- config.delete?.mutation,
442
- config.bulkDelete?.mutation
443
- ]).filter((m) => typeof m !== "string" && m !== void 0);
444
- const hasMutation = endpoints.length > 0;
445
- const hasAclCheck = resolver.options.checkAcl && endpoints.some((e) => e.acl);
446
- const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
447
- const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
448
- const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
449
- const nativeClient = resolver.options.restClient === "native";
450
- const hasAxiosDefaultImport = !nativeClient && endpoints.some((e) => e.mediaUpload);
451
- const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport);
452
- const axiosImport = {
453
- defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
454
- bindings: [],
455
- typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
456
- from: "axios"
457
- };
458
- const nativeImport = {
459
- bindings: [],
460
- typeBindings: nativeClient && hasAxiosRequestConfig ? [getRequestConfigTypeName("native")] : [],
461
- from: REST_PACKAGE_IMPORT_PATH
462
- };
463
- const appRestClientImport = {
464
- bindings: [APP_REST_CLIENT_NAME],
465
- from: getAppRestClientImportPath(resolver.options)
466
- };
467
- const endpointsImports = getEndpointsImports({
468
- tag,
469
- endpoints,
470
- options: resolver.options
471
- });
472
- const queryImport = {
473
- bindings: [QUERY_HOOKS.mutation],
474
- from: "@tanstack/react-query"
475
- };
476
- const queryTypesImport = {
477
- bindings: [...hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
478
- typeBindings: [QUERY_OPTIONS_TYPES.mutation],
479
- from: getQueryTypesImportPath(resolver.options)
480
- };
481
- const mutationEffectsImport = {
482
- bindings: [MUTATION_EFFECTS.hookName],
483
- typeBindings: [MUTATION_EFFECTS.optionsType],
484
- from: resolver.options.mutationEffectsImportPath
485
- };
486
- const queryModulesImport = {
487
- bindings: [QUERY_MODULE_ENUM],
488
- from: getQueryModulesImportPath(resolver.options)
489
- };
490
- const aclCheckImport = {
491
- bindings: [ACL_CHECK_HOOK],
492
- from: resolver.options.aclCheckImportPath
493
- };
494
- const hasDynamicInputsImport = configs.some((config) => config.readAll.filters || config.create?.inputDefs || config.update?.inputDefs);
495
- const dynamicInputsImport = {
496
- bindings: [BUILDERS_UTILS.dynamicInputs],
497
- from: resolver.options.dynamicInputsImportPath
498
- };
499
- const hasDynamicColumnsImport = configs.some((config) => config.readAll.columns);
500
- const dynamicColumnsImport = {
501
- bindings: [BUILDERS_UTILS.dynamicColumns],
502
- from: resolver.options.dynamicColumnsImportPath
503
- };
504
- const lines = [];
505
- if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
506
- if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
507
- if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
508
- if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
509
- if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
510
- if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
511
- for (const modelsImport of modelsImports) lines.push(renderImport$3(modelsImport));
512
- for (const queriesImport of queriesImports) lines.push(renderImport$3(queriesImport));
513
- for (const endpointsImport of endpointsImports) lines.push(renderImport$3(endpointsImport));
514
- if (hasMutation) {
515
- lines.push(renderImport$3(queryImport));
516
- lines.push(renderImport$3(queryTypesImport));
517
- if (hasMutationEffects) {
518
- lines.push(renderImport$3(queryModulesImport));
519
- lines.push(renderImport$3(mutationEffectsImport));
520
- }
521
- if (hasAclCheck) lines.push(renderImport$3(aclCheckImport));
522
- }
523
- for (const aclImport of aclImports) lines.push(renderImport$3(aclImport));
524
- lines.push("");
525
- if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
526
- type: "configs",
527
- tag,
528
- options: resolver.options
529
- })} {`);
530
- for (const config of configs) {
531
- lines.push(renderBuilderConfig(config, generateTypeParams));
532
- lines.push("");
533
- }
534
- if (resolver.options.tsNamespaces) lines.push("}");
535
- return lines.join("\n").trimEnd() + "\n";
536
- }
537
- function renderImport$3(importData) {
538
- const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
539
- const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
540
- return `import${importData.typeOnly ? " type" : ""} ${names} from "${importData.from}";`;
541
- }
542
- function renderInputsConfig(inputsConfig) {
543
- const lines = [];
544
- lines.push("{");
545
- lines.push(` schema: ${inputsConfig.schema},`);
546
- lines.push(" options: {");
547
- lines.push(" inputs: {");
548
- for (const key of Object.keys(inputsConfig.options.inputs)) lines.push(` ${key}: true,`);
549
- lines.push(" },");
550
- lines.push(" },");
551
- lines.push("}");
552
- return lines.join("\n");
553
- }
554
- function renderColumnsConfig(columnsConfig) {
555
- const lines = [];
556
- lines.push("{");
557
- lines.push(` schema: ${columnsConfig.schema},`);
558
- lines.push(" options: {");
559
- lines.push(" columns: {");
560
- for (const key of Object.keys(columnsConfig.options.columns)) lines.push(` ${key}: true,`);
561
- lines.push(" },");
562
- if (columnsConfig.options.sortable) lines.push(` sortable: ${columnsConfig.options.sortable},`);
563
- lines.push(" },");
564
- lines.push("}");
565
- return lines.join("\n");
566
- }
567
- function renderMutationContent(resolver, endpoint, tag) {
568
- const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
569
- const hasMutationEffects = resolver.options.mutationEffects;
570
- const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError;
571
- const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
572
- const endpointTag = getEndpointTag(endpoint, resolver.options);
573
- const endpointParams = mapEndpointParamsToFunctionParams(resolver, endpoint, {
574
- includeFileParam: true,
575
- modelNamespaceTag: endpointTag
576
- });
577
- const endpointParamsStr = endpointParams.map((p) => `${p.name}${p.required ? "" : "?"}: ${p.type}`).join("; ");
578
- const destructuredMutationArgs = endpointParams.map((p) => p.name).join(", ");
579
- const resolvedEndpointArgs = mapEndpointParamsToFunctionParams(resolver, endpoint, { modelNamespaceTag: endpointTag }).map((p) => p.name).join(", ");
580
- const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
581
- const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
582
- const lines = [];
583
- lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
584
- if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
585
- if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
586
- if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
587
- lines.push("");
588
- lines.push(` return ${QUERY_HOOKS.mutation}({`);
589
- const mutationFnArg = destructuredMutationArgs ? `{ ${destructuredMutationArgs}${endpoint.mediaUpload ? `${destructuredMutationArgs ? ", " : ""}abortController, onUploadProgress` : ""} }` : "";
590
- lines.push(` mutationFn: ${endpoint.mediaUpload ? "async " : ""}(${mutationFnArg}) => {`);
591
- if (hasAclCheck) lines.push(renderAclCheckCall(resolver, endpoint, void 0, " "));
592
- if (endpoint.mediaUpload) lines.push(...renderMediaUploadMutationBody({
593
- resolver,
594
- endpointFunction,
595
- resolvedEndpointArgs
596
- }).map((line) => ` ${line}`));
597
- else lines.push(` return ${endpointFunction}(${destructuredMutationArgs}${hasAxiosRequestConfig ? `${destructuredMutationArgs ? ", " : ""}config` : ""});`);
598
- lines.push(" },");
599
- lines.push(" ...options,");
600
- if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
601
- if (hasMutationEffects) {
602
- lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
603
- lines.push(" await runMutationEffects(resData, variables, options);");
604
- lines.push(" options?.onSuccess?.(resData, variables, onMutateResult, context);");
605
- lines.push(" },");
606
- }
607
- lines.push(" });");
608
- lines.push("}");
609
- return lines.map((line) => " " + line).join("\n").trimStart();
610
- }
611
- function renderBuilderConfig(config, params) {
612
- const { resolver, tag } = params;
613
- const lines = [];
614
- lines.push(`export const ${config.name} = {`);
615
- lines.push(" meta: {");
616
- lines.push(` title: "${config.title}",`);
617
- lines.push(" },");
618
- lines.push(" readAll: {");
619
- if (config.readAll.acl) lines.push(` acl: ${config.readAll.acl},`);
620
- lines.push(` schema: ${config.readAll.columns.schema},`);
621
- lines.push(` paginated: ${config.readAll.paginated},`);
622
- if (config.readAll.infinite) lines.push(` infinite: ${config.readAll.infinite},`);
623
- if (config.readAll.filters) {
624
- lines.push(" filters: {");
625
- lines.push(` schema: ${config.readAll.filters.schema},`);
626
- lines.push(` filterDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.readAll.filters)})`);
627
- lines.push(" },");
628
- }
629
- lines.push(` columns: ${BUILDERS_UTILS.dynamicColumns}(${renderColumnsConfig(config.readAll.columns)}),`);
630
- lines.push(" },");
631
- if (config.read) {
632
- lines.push(" read: {");
633
- if (config.read.acl) lines.push(` acl: ${config.read.acl},`);
634
- lines.push(` schema: ${config.read.schema},`);
635
- lines.push(` query: ${config.read.query},`);
636
- lines.push(" },");
637
- }
638
- if (config.create) {
639
- lines.push(" create: {");
640
- if (config.create.acl) lines.push(` acl: ${config.create.acl},`);
641
- if (config.create.schema) lines.push(` schema: ${config.create.schema},`);
642
- lines.push(` mutation: ${typeof config.create.mutation === "string" ? config.create.mutation : renderMutationContent(resolver, config.create.mutation, tag)},`);
643
- if (config.create.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.create.inputDefs)})`);
644
- lines.push(" },");
645
- }
646
- if (config.update) {
647
- lines.push(" update: {");
648
- if (config.update.acl) lines.push(` acl: ${config.update.acl},`);
649
- if (config.update.schema) lines.push(` schema: ${config.update.schema},`);
650
- lines.push(` mutation: ${typeof config.update.mutation === "string" ? config.update.mutation : renderMutationContent(resolver, config.update.mutation, tag)},`);
651
- if (config.update.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.update.inputDefs)})`);
652
- lines.push(" },");
653
- }
654
- if (config.delete) {
655
- lines.push(" delete: {");
656
- if (config.delete.acl) lines.push(` acl: ${config.delete.acl},`);
657
- lines.push(` mutation: ${typeof config.delete.mutation === "string" ? config.delete.mutation : renderMutationContent(resolver, config.delete.mutation, tag)},`);
658
- lines.push(" },");
659
- }
660
- if (config.bulkDelete) {
661
- lines.push(" bulkDelete: {");
662
- if (config.bulkDelete.acl) lines.push(` acl: ${config.bulkDelete.acl},`);
663
- if (config.bulkDelete.schema) lines.push(` schema: ${config.bulkDelete.schema},`);
664
- lines.push(` mutation: ${typeof config.bulkDelete.mutation === "string" ? config.bulkDelete.mutation : renderMutationContent(resolver, config.bulkDelete.mutation, tag)},`);
665
- if (config.bulkDelete.inputDefs) lines.push(` inputDefs: ${BUILDERS_UTILS.dynamicInputs}(${renderInputsConfig(config.bulkDelete.inputDefs)})`);
666
- lines.push(" },");
667
- }
668
- lines.push("};");
669
- return lines.join("\n");
670
- }
671
- //#endregion
672
212
  //#region src/generators/generate/generateEndpoints.ts
673
213
  function generateEndpoints({ resolver, data, tag }) {
674
214
  const nativeContent = resolver.getNativeRenderedEndpoints?.(tag);
@@ -801,6 +341,83 @@ function renderEndpointConfig(resolver, endpoint, modelNamespaceTag) {
801
341
  return lines.join("\n ");
802
342
  }
803
343
  //#endregion
344
+ //#region src/generators/utils/generate/generate.lazy.utils.ts
345
+ const ONCE_HELPER_LINES = [
346
+ "const once = <T>(create: () => T) => {",
347
+ " let value: T | undefined;",
348
+ " return () => (value ??= create());",
349
+ "};"
350
+ ];
351
+ const isIdentifierChar = (char) => /[A-Za-z0-9_$]/.test(char);
352
+ const findLiteralEnd = (code, start, quote) => {
353
+ let index = start + 1;
354
+ while (index < code.length) {
355
+ const char = code[index];
356
+ if (char === "\\") {
357
+ index += 2;
358
+ continue;
359
+ }
360
+ index += 1;
361
+ if (char === quote) break;
362
+ }
363
+ return Math.min(index, code.length);
364
+ };
365
+ const findRegexEnd = (code, start) => {
366
+ let escaped = false;
367
+ let characterClass = false;
368
+ for (let index = start + 1; index < code.length; index += 1) {
369
+ const char = code[index];
370
+ if (escaped) {
371
+ escaped = false;
372
+ continue;
373
+ }
374
+ if (char === "\\") {
375
+ escaped = true;
376
+ continue;
377
+ }
378
+ if (char === "[") characterClass = true;
379
+ if (char === "]") characterClass = false;
380
+ if (char === "/" && !characterClass) return index + 1;
381
+ }
382
+ return code.length;
383
+ };
384
+ /**
385
+ * Rewrites bare references to sibling schemas (`PetSchema`) into factory calls (`PetSchema()`).
386
+ * Member accesses (`CommonModels.PetSchema`, `.enum`), object keys and literal values are left alone.
387
+ */
388
+ function callLazySchemaReferences(code, schemaNames) {
389
+ let output = "";
390
+ let index = 0;
391
+ while (index < code.length) {
392
+ const char = code[index];
393
+ if (char === "\"" || char === "'" || char === "`") {
394
+ const end = findLiteralEnd(code, index, char);
395
+ output += code.slice(index, end);
396
+ index = end;
397
+ continue;
398
+ }
399
+ if (char === "/" && output.trimEnd().endsWith(".regex(")) {
400
+ const end = findRegexEnd(code, index);
401
+ output += code.slice(index, end);
402
+ index = end;
403
+ continue;
404
+ }
405
+ if (isIdentifierChar(char)) {
406
+ let end = index + 1;
407
+ while (end < code.length && isIdentifierChar(code[end])) end += 1;
408
+ const identifier = code.slice(index, end);
409
+ const isMemberAccess = output.endsWith(".");
410
+ const isObjectKey = code.slice(end).trimStart().startsWith(":");
411
+ output += schemaNames.has(identifier) && !isMemberAccess && !isObjectKey ? `${identifier}()` : identifier;
412
+ index = end;
413
+ continue;
414
+ }
415
+ output += char;
416
+ index += 1;
417
+ }
418
+ return output;
419
+ }
420
+ //#endregion
804
421
  //#region src/generators/generate/generateModels.ts
805
422
  function generateModels({ resolver, data, tag }) {
806
423
  const nativeContent = resolver.getNativeRenderedModels?.(tag);
@@ -836,6 +453,12 @@ function generateModels({ resolver, data, tag }) {
836
453
  lines.push(renderImport$1(ZOD_IMPORT));
837
454
  for (const modelsImport of modelsImports) lines.push(renderImport$1(modelsImport));
838
455
  lines.push("");
456
+ if (resolver.options.lazySchemas && resolver.options.tsNamespaces) return renderLazyModels({
457
+ resolver,
458
+ tag,
459
+ zodSchemasData,
460
+ lines
461
+ });
839
462
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
840
463
  type: "models",
841
464
  tag,
@@ -860,6 +483,50 @@ function generateModels({ resolver, data, tag }) {
860
483
  if (resolver.options.tsNamespaces) lines.push("}");
861
484
  return lines.join("\n").trimEnd() + "\n";
862
485
  }
486
+ function renderLazyModels({ resolver, tag, zodSchemasData, lines }) {
487
+ const namespace = getNamespaceName({
488
+ type: "models",
489
+ tag,
490
+ options: resolver.options
491
+ });
492
+ const schemaNames = new Set(Object.keys(zodSchemasData));
493
+ const members = [];
494
+ const types = [];
495
+ lines.push(...ONCE_HELPER_LINES, "");
496
+ for (const [name, zodSchema] of Object.entries(zodSchemasData)) {
497
+ const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
498
+ const typeAnnotation = zodSchema.isCircular ? `: () => z.ZodObject<z.ZodRawShape> & z.ZodType<${namespace}.${inferredTypeName}>` : "";
499
+ const schemaCode = resolver.options.compileSchemas && !zodSchema.isCircular ? `z.compile(${zodSchema.code})` : zodSchema.code;
500
+ lines.push(`const ${name}${typeAnnotation} = once(() => ${callLazySchemaReferences(schemaCode, schemaNames)});`);
501
+ members.push(...indent(renderModelJsDocs({
502
+ name,
503
+ zodSchema,
504
+ tag,
505
+ resolver
506
+ }).split("\n")));
507
+ members.push(...renderLazyMember(name, `${name}()`));
508
+ if (zodSchema.isCircular && zodSchema.schemaObj) types.push(` export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
509
+ else types.push(` export type ${inferredTypeName} = z.infer<typeof ${namespace}.${name}>;`);
510
+ if (zodSchema.isEnum) {
511
+ lines.push(`const ${inferredTypeName} = once(() => ${name}().enum);`);
512
+ members.push(...renderLazyMember(inferredTypeName, `${inferredTypeName}()`));
513
+ }
514
+ }
515
+ lines.push("");
516
+ lines.push(`export const ${namespace} = {`, ...members, "};");
517
+ lines.push(`export declare namespace ${namespace} {`, ...types, "}");
518
+ return lines.join("\n") + "\n";
519
+ }
520
+ function renderLazyMember(name, value) {
521
+ return [
522
+ ` get ${name}() {`,
523
+ ` return ${value};`,
524
+ ` },`
525
+ ];
526
+ }
527
+ function indent(lines) {
528
+ return lines.map((line) => ` ${line}`);
529
+ }
863
530
  function renderSchemaType(schema, resolver) {
864
531
  if (isReferenceObject(schema)) {
865
532
  const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
@@ -918,6 +585,20 @@ function renderModelsProxy({ resolver, data, tag }) {
918
585
  })}`;
919
586
  const inferredTypeNames = schemaNames.map((schemaName) => getZodSchemaInferedTypeName(schemaName, resolver.options));
920
587
  const enumInferredTypeNames = schemaNames.filter((schemaName) => isEnumZodSchema(commonZodSchemas[schemaName] ?? "")).map((schemaName) => getZodSchemaInferedTypeName(schemaName, resolver.options));
588
+ if (resolver.options.tsNamespaces && resolver.options.lazySchemas) {
589
+ const lines = [];
590
+ lines.push(`import { ${commonNamespace} } from "${commonModelsPath}";`);
591
+ lines.push("");
592
+ lines.push(`export const ${modelsNamespace} = {`);
593
+ for (const schemaName of schemaNames) lines.push(...renderLazyMember(schemaName, `${commonNamespace}.${schemaName}`));
594
+ for (const enumName of enumInferredTypeNames) lines.push(...renderLazyMember(enumName, `${commonNamespace}.${enumName}`));
595
+ lines.push("};");
596
+ lines.push(`export declare namespace ${modelsNamespace} {`);
597
+ for (const typeName of inferredTypeNames) lines.push(` export type ${typeName} = ${commonNamespace}.${typeName};`);
598
+ lines.push("}");
599
+ lines.push("");
600
+ return lines.join("\n");
601
+ }
921
602
  if (resolver.options.tsNamespaces) {
922
603
  const lines = [];
923
604
  lines.push(`import { ${commonNamespace} } from "${commonModelsPath}";`);
@@ -980,6 +661,22 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
980
661
  return lines.join("\n");
981
662
  }
982
663
  //#endregion
664
+ //#region src/generators/const/queries.const.ts
665
+ const QUERY_HOOKS = {
666
+ query: "useQuery",
667
+ infiniteQuery: "useInfiniteQuery",
668
+ mutation: "useMutation"
669
+ };
670
+ const QUERY_IMPORT = {
671
+ bindings: [
672
+ QUERY_HOOKS.query,
673
+ QUERY_HOOKS.infiniteQuery,
674
+ QUERY_HOOKS.mutation
675
+ ],
676
+ from: "@tanstack/react-query"
677
+ };
678
+ const QUERIES_MODULE_NAME = "moduleName";
679
+ //#endregion
983
680
  //#region src/generators/generate/generateQueries.ts
984
681
  const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
985
682
  const workspaceParamNamesCache = /* @__PURE__ */ new WeakMap();
@@ -1817,6 +1514,7 @@ function generateQueryModules({ resolver, data }) {
1817
1514
  lines.push("}");
1818
1515
  lines.push("");
1819
1516
  lines.push("declare global {");
1517
+ lines.push(" interface OpenApiCodegenQueryModules { queryModule: QueryModule }");
1820
1518
  lines.push(" interface OpenApiCodegenQueryModuleMutations extends QueryModuleMutations {}");
1821
1519
  lines.push("}");
1822
1520
  return lines.join("\n");
@@ -2085,15 +1783,13 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler, nativeSource)
2085
1783
  "models",
2086
1784
  ...shouldGenerateEndpoints ? ["endpoints"] : [],
2087
1785
  "queries",
2088
- ...resolver.options.acl ? ["acl"] : [],
2089
- ...resolver.options.builderConfigs ? ["configs"] : []
1786
+ ...resolver.options.acl ? ["acl"] : []
2090
1787
  ];
2091
1788
  const generateFunctions = {
2092
1789
  ["models"]: generateModels,
2093
1790
  ["endpoints"]: generateEndpoints,
2094
1791
  ["queries"]: generateQueries,
2095
- ["acl"]: generateAcl,
2096
- ["configs"]: generateConfigs
1792
+ ["acl"]: generateAcl
2097
1793
  };
2098
1794
  data.forEach((_, tag) => {
2099
1795
  generateTypes.forEach((type) => {
@@ -2123,4 +1819,4 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler, nativeSource)
2123
1819
  return generateFilesData;
2124
1820
  }
2125
1821
  //#endregion
2126
- export { generateCodeFromOpenAPIDoc_exports as n, generateCodeFromOpenAPIDoc as t };
1822
+ export { generateCodeFromOpenAPIDoc_exports as n, getQueryName as r, generateCodeFromOpenAPIDoc as t };