@povio/openapi-codegen-cli 4.0.0-rc.2 → 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.
Files changed (31) hide show
  1. package/README.md +5 -5
  2. package/dist/{config-CiLFKLAY.d.mts → config-BSYiW3xV.d.mts} +1 -1
  3. package/dist/config.d.mts +2 -2
  4. package/dist/{generate.runner-BuSwqeff.mjs → generate.runner-BMqvEp4L.mjs} +6 -110
  5. package/dist/{generate.utils-BJxdEik8.cjs → generate.utils-D4eHo3wO.cjs} +3 -269
  6. package/dist/{generateCodeFromOpenAPIDoc-Cc34c6zl.cjs → generateCodeFromOpenAPIDoc-DRLE112u.cjs} +104 -528
  7. package/dist/{generateCodeFromOpenAPIDoc-B68pSpWW.mjs → generateCodeFromOpenAPIDoc-oe5uj0P4.mjs} +61 -502
  8. package/dist/generator.d.mts +1 -1
  9. package/dist/generator.mjs +3 -3
  10. package/dist/{getDataFromOpenAPIDoc-B_URkLm6.mjs → getDataFromOpenAPIDoc-BqEeVt1w.mjs} +19 -2
  11. package/dist/index.d.mts +4 -4
  12. package/dist/index.mjs +1 -1
  13. package/dist/metro.cjs +3 -3
  14. package/dist/metro.d.mts +3 -3
  15. package/dist/metro.mjs +1 -1
  16. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  17. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  18. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  19. package/dist/{openapi-codegen.runner-G25v_q9z.mjs → openapi-codegen.runner-R_Dnb1mt.mjs} +1 -1
  20. package/dist/{openapi-source.runner-DIOvAX_R.d.mts → openapi-source.runner-DEtp4qCv.d.mts} +1 -1
  21. package/dist/{options-X0zju7gw.d.mts → options-BV720uS2.d.mts} +2 -10
  22. package/dist/query.d.mts +3 -3
  23. package/dist/query.mjs +1 -1
  24. package/dist/{queryConfig.context-yl7x_NdW.d.mts → queryConfig.context-BbLtDfIH.d.mts} +25 -7
  25. package/dist/sh.mjs +3 -8
  26. package/dist/tiny.d.mts +1 -1
  27. package/dist/{useMutationEffects-PB1fvKWM.mjs → useMutationEffects-CNVMVAbn.mjs} +1 -1
  28. package/dist/{useMutationEffects-CjGlHDg_.d.mts → useMutationEffects-CmGB4BOV.d.mts} +1 -1
  29. package/dist/vite.d.mts +3 -3
  30. package/dist/vite.mjs +1 -1
  31. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-B_URkLm6.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-BuSwqeff.mjs";
1
+ import { a as isQuery, i as isMutation, n as getDestructuredVariables, r as isInfiniteQuery, s as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BqEeVt1w.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-BMqvEp4L.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);
@@ -980,6 +520,22 @@ function renderModelJsDocs({ name, zodSchema, tag, resolver }) {
980
520
  return lines.join("\n");
981
521
  }
982
522
  //#endregion
523
+ //#region src/generators/const/queries.const.ts
524
+ const QUERY_HOOKS = {
525
+ query: "useQuery",
526
+ infiniteQuery: "useInfiniteQuery",
527
+ mutation: "useMutation"
528
+ };
529
+ const QUERY_IMPORT = {
530
+ bindings: [
531
+ QUERY_HOOKS.query,
532
+ QUERY_HOOKS.infiniteQuery,
533
+ QUERY_HOOKS.mutation
534
+ ],
535
+ from: "@tanstack/react-query"
536
+ };
537
+ const QUERIES_MODULE_NAME = "moduleName";
538
+ //#endregion
983
539
  //#region src/generators/generate/generateQueries.ts
984
540
  const endpointParamMappingCache = /* @__PURE__ */ new WeakMap();
985
541
  const workspaceParamNamesCache = /* @__PURE__ */ new WeakMap();
@@ -1815,6 +1371,11 @@ function generateQueryModules({ resolver, data }) {
1815
1371
  lines.push(` [QueryModule.${module.tag}]: MutationEffectsOf<${hooks}>;`);
1816
1372
  }
1817
1373
  lines.push("}");
1374
+ lines.push("");
1375
+ lines.push("declare global {");
1376
+ lines.push(" interface OpenApiCodegenQueryModules { queryModule: QueryModule }");
1377
+ lines.push(" interface OpenApiCodegenQueryModuleMutations extends QueryModuleMutations {}");
1378
+ lines.push("}");
1818
1379
  return lines.join("\n");
1819
1380
  }
1820
1381
  //#endregion
@@ -2081,15 +1642,13 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler, nativeSource)
2081
1642
  "models",
2082
1643
  ...shouldGenerateEndpoints ? ["endpoints"] : [],
2083
1644
  "queries",
2084
- ...resolver.options.acl ? ["acl"] : [],
2085
- ...resolver.options.builderConfigs ? ["configs"] : []
1645
+ ...resolver.options.acl ? ["acl"] : []
2086
1646
  ];
2087
1647
  const generateFunctions = {
2088
1648
  ["models"]: generateModels,
2089
1649
  ["endpoints"]: generateEndpoints,
2090
1650
  ["queries"]: generateQueries,
2091
- ["acl"]: generateAcl,
2092
- ["configs"]: generateConfigs
1651
+ ["acl"]: generateAcl
2093
1652
  };
2094
1653
  data.forEach((_, tag) => {
2095
1654
  generateTypes.forEach((type) => {
@@ -2119,4 +1678,4 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler, nativeSource)
2119
1678
  return generateFilesData;
2120
1679
  }
2121
1680
  //#endregion
2122
- export { generateCodeFromOpenAPIDoc_exports as n, generateCodeFromOpenAPIDoc as t };
1681
+ export { generateCodeFromOpenAPIDoc_exports as n, getQueryName as r, generateCodeFromOpenAPIDoc as t };
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-X0zju7gw.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-BV720uS2.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
  //#region src/generators/types/metadata.d.ts
4
4
  interface GenerateParams {
@@ -1,6 +1,6 @@
1
- import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-B68pSpWW.mjs";
2
- import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-B_URkLm6.mjs";
3
- import { H as getQueryName, Ht as getNamespaceName, Mn as formatTag, O as getTagImportPath, S as getTsTypeBase, Xt as isMediaTypeAllowed, Zt as isParamMediaTypeAllowed, bt as invalidVariableNameCharactersToCamel, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, t as getOpenApiDoc, u as isMutation, x as getSchemaTsMetaType } from "./generate.runner-BuSwqeff.mjs";
1
+ import { r as getQueryName, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-oe5uj0P4.mjs";
2
+ import { a as isQuery, i as isMutation, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BqEeVt1w.mjs";
3
+ import { Et as isParamMediaTypeAllowed, Tt as isMediaTypeAllowed, X as invalidVariableNameCharactersToCamel, Y as DEFAULT_GENERATE_OPTIONS, _ as getSchemaTsMetaType, _t as getNamespaceName, sn as formatTag, t as getOpenApiDoc, v as getTsTypeBase, w as getTagImportPath } from "./generate.runner-BMqvEp4L.mjs";
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
5
5
  async function getMetadataFromOpenAPIDoc(openApiDoc, options) {
6
6
  const { resolver, data } = await getDataFromOpenAPIDoc(openApiDoc, options);