@povio/openapi-codegen-cli 4.0.0-rc.4 → 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 (28) hide show
  1. package/README.md +38 -10
  2. package/dist/{config-BSYiW3xV.d.mts → config-D8ANLlqk.d.mts} +1 -1
  3. package/dist/config.d.mts +2 -2
  4. package/dist/{generate.runner-BMqvEp4L.mjs → generate.runner-LDL6Lbgl.mjs} +3 -1
  5. package/dist/{generate.utils-D4eHo3wO.cjs → generate.utils-BFeGvk98.cjs} +1 -0
  6. package/dist/{generateCodeFromOpenAPIDoc-oe5uj0P4.mjs → generateCodeFromOpenAPIDoc-B7VWwIbb.mjs} +143 -2
  7. package/dist/{generateCodeFromOpenAPIDoc-DRLE112u.cjs → generateCodeFromOpenAPIDoc-CpAdx6I3.cjs} +142 -1
  8. package/dist/generator.d.mts +1 -1
  9. package/dist/generator.mjs +3 -3
  10. package/dist/{getDataFromOpenAPIDoc-BqEeVt1w.mjs → getDataFromOpenAPIDoc-C0iehdg8.mjs} +1 -1
  11. package/dist/index.d.mts +4 -4
  12. package/dist/metro.cjs +3 -2
  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-R_Dnb1mt.mjs → openapi-codegen.runner-CmW9oZdT.mjs} +1 -1
  19. package/dist/{openapi-source.runner-DEtp4qCv.d.mts → openapi-source.runner-DES1kzvS.d.mts} +1 -1
  20. package/dist/{options-BV720uS2.d.mts → options-B7-eMFcv.d.mts} +2 -0
  21. package/dist/query.d.mts +3 -3
  22. package/dist/{queryConfig.context-BbLtDfIH.d.mts → queryConfig.context-DwVQWbtL.d.mts} +11 -6
  23. package/dist/sh.mjs +8 -3
  24. package/dist/tiny.d.mts +1 -1
  25. package/dist/{useMutationEffects-CmGB4BOV.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
package/README.md CHANGED
@@ -36,6 +36,31 @@ export default {
36
36
  };
37
37
  ```
38
38
 
39
+ ## Lazy schemas
40
+
41
+ With `tsNamespaces` enabled, every schema of a models namespace is built the moment the module is imported, even when the importer only needs one of them. Set `lazySchemas: true` (or pass `--lazySchemas`) to build each schema on first access instead:
42
+
43
+ ```typescript
44
+ // Generated with lazySchemas: true
45
+ const once = <T>(create: () => T) => {
46
+ let value: T | undefined;
47
+ return () => (value ??= create());
48
+ };
49
+
50
+ const PetSchema = once(() => z.object({ id: z.int(), category: CategorySchema() }));
51
+
52
+ export const PetModels = {
53
+ get PetSchema() {
54
+ return PetSchema();
55
+ },
56
+ };
57
+ export declare namespace PetModels {
58
+ export type Pet = z.infer<typeof PetModels.PetSchema>;
59
+ }
60
+ ```
61
+
62
+ `PetModels.PetSchema` stays a regular Zod schema (`.extend`, `.shape`, `.pick` all work and return the same instance on every access), `PetModels.Pet` keeps resolving as a type, and `modelsInCommon` proxies forward to the shared namespace lazily as well. The option requires `tsNamespaces` and is honored by both the TypeScript and native generators. It helps cold starts of apps that import large model modules but render only a slice of them.
63
+
39
64
  ## Configuration Files
40
65
 
41
66
  The CLI supports TypeScript configuration files to simplify command execution and provide consistent settings with full type safety. Configuration files are automatically discovered in your project root.
@@ -100,6 +125,7 @@ bunx openapi-codegen generate --config my-config.ts
100
125
  --tsPath (Requires `--importPath` to be 'ts') Typescript import path (default: '@/data')
101
126
  --removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (default: 'Controller_')
102
127
  --compileSchemas Eagerly compile non-recursive Zod schemas (default: false)
128
+ --lazySchemas Build namespace model schemas on first access instead of at import; requires `--tsNamespaces` (default: false)
103
129
  --extractEnums Extract enums into separate Zod schemas (default: true)
104
130
  --modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
105
131
  --replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
@@ -342,6 +368,8 @@ const config: OpenAPICodegenConfig = {
342
368
  // modelsOnly: true,
343
369
  // 4) Keep all model declarations in common.models and generate per-module model proxies
344
370
  // modelsInCommon: true,
371
+ // 5) Build each namespace schema on first access instead of at import (requires tsNamespaces)
372
+ // lazySchemas: true,
345
373
  };
346
374
  ```
347
375
 
@@ -592,17 +620,17 @@ export class JSONDto {
592
620
 
593
621
  Use package subpaths for runtime imports. Pure `import type` imports may use the package root.
594
622
 
595
- | Runtime exports | Subpath |
596
- | --- | --- |
597
- | `AuthContext`, `AuthGuard` | `/auth` |
598
- | `AbilityContext`, `useAclCheck`, `Can`, `createAclGuard` | `/acl` |
599
- | `ErrorHandler`, `SharedErrorHandler`, `ApplicationException`, `DomainErrorRegistry` | `/errors` |
600
- | `useMutationEffects`, `OpenApiQueryConfig` | `/query` |
623
+ | Runtime exports | Subpath |
624
+ | -------------------------------------------------------------------------------------------- | --------- |
625
+ | `AuthContext`, `AuthGuard` | `/auth` |
626
+ | `AbilityContext`, `useAclCheck`, `Can`, `createAclGuard` | `/acl` |
627
+ | `ErrorHandler`, `SharedErrorHandler`, `ApplicationException`, `DomainErrorRegistry` | `/errors` |
628
+ | `useMutationEffects`, `OpenApiQueryConfig` | `/query` |
601
629
  | `OpenApiRouter`, `OpenApiWorkspaceContext`, `useWorkspaceContext`, translation configuration | `/config` |
602
- | `ZodExtended` | `/zod` |
603
- | `HttpError`, transport types | `/rest` |
604
- | `NativeRestClient` | `/native` |
605
- | `RestClient`, `RestInterceptor` (Axios transport) | `/axios` |
630
+ | `ZodExtended` | `/zod` |
631
+ | `HttpError`, transport types | `/rest` |
632
+ | `NativeRestClient` | `/native` |
633
+ | `RestClient`, `RestInterceptor` (Axios transport) | `/axios` |
606
634
 
607
635
  For example: `import { AuthContext, AuthGuard } from "@povio/openapi-codegen-cli/auth"`.
608
636
  Custom application helpers should import error helpers from `/errors`, `AbilityContext` from `/acl`, and mutation effects from `/query`.
@@ -1,4 +1,4 @@
1
- import { t as GenerateOptions } from "./options-BV720uS2.mjs";
1
+ import { t as GenerateOptions } from "./options-B7-eMFcv.mjs";
2
2
  //#region src/generators/types/config.d.ts
3
3
  type OpenAPICodegenConfig = Partial<GenerateOptions>;
4
4
  //#endregion
package/dist/config.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { i as resources, n as configureTranslations, r as ns, t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
2
2
  import { n as useWorkspaceContext, r as OpenApiRouter, t as OpenApiWorkspaceContext } from "./workspace.context-isVY9ves.mjs";
3
- import { a as MutationEffectsTypes, c as RegisteredQueryModule, i as MutationEffectsOf, n as InvalidationMapFunc, o as OpenApiQueryConfig, r as MergedMutationVariables, s as QueryModule, t as InvalidationMap } from "./queryConfig.context-BbLtDfIH.mjs";
4
- export { type InvalidationMap, type InvalidationMapFunc, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsTypes, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RegisteredQueryModule, type TranslateFunction, configureTranslations, ns, resources, useWorkspaceContext };
3
+ import { a as MergedMutationVariables, c as OpenApiQueryConfig, i as MergedMutationValues, l as QueryModule, n as InvalidationMapFunc, o as MutationEffectsOf, r as MergedMutationData, s as MutationEffectsTypes, t as InvalidationMap, u as RegisteredQueryModule } from "./queryConfig.context-DwVQWbtL.mjs";
4
+ export { type InvalidationMap, type InvalidationMapFunc, type MergedMutationData, type MergedMutationValues, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsTypes, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RegisteredQueryModule, type TranslateFunction, configureTranslations, ns, resources, useWorkspaceContext };
@@ -471,6 +471,7 @@ const DEFAULT_GENERATE_OPTIONS = {
471
471
  modelsOnly: false,
472
472
  standalone: false,
473
473
  compileSchemas: false,
474
+ lazySchemas: false,
474
475
  schemaSuffix: SCHEMA_SUFFIX,
475
476
  enumSuffix: ENUM_SUFFIX,
476
477
  modelsInCommon: false,
@@ -1345,6 +1346,7 @@ function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, in
1345
1346
  workspaceContext: workspaceContext?.split(",")
1346
1347
  });
1347
1348
  if (resolvedConfig.modelsInCommon && resolvedConfig.modelsInModules) throw new Error("modelsInCommon and modelsInModules cannot both be enabled");
1349
+ if (resolvedConfig.lazySchemas && !resolvedConfig.tsNamespaces) throw new Error("lazySchemas requires tsNamespaces");
1348
1350
  resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
1349
1351
  resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
1350
1352
  return resolvedConfig;
@@ -1472,7 +1474,7 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
1472
1474
  const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
1473
1475
  if (nativeFiles) return nativeFiles;
1474
1476
  }
1475
- const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-oe5uj0P4.mjs").then((n) => n.n);
1477
+ const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-B7VWwIbb.mjs").then((n) => n.n);
1476
1478
  return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
1477
1479
  source: nativeInput.source,
1478
1480
  yaml: nativeInput.yaml
@@ -100,6 +100,7 @@ const DEFAULT_GENERATE_OPTIONS = {
100
100
  modelsOnly: false,
101
101
  standalone: false,
102
102
  compileSchemas: false,
103
+ lazySchemas: false,
103
104
  schemaSuffix: SCHEMA_SUFFIX,
104
105
  enumSuffix: ENUM_SUFFIX,
105
106
  modelsInCommon: false,
@@ -1,5 +1,5 @@
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";
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;
@@ -341,6 +341,83 @@ function renderEndpointConfig(resolver, endpoint, modelNamespaceTag) {
341
341
  return lines.join("\n ");
342
342
  }
343
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
344
421
  //#region src/generators/generate/generateModels.ts
345
422
  function generateModels({ resolver, data, tag }) {
346
423
  const nativeContent = resolver.getNativeRenderedModels?.(tag);
@@ -376,6 +453,12 @@ function generateModels({ resolver, data, tag }) {
376
453
  lines.push(renderImport$1(ZOD_IMPORT));
377
454
  for (const modelsImport of modelsImports) lines.push(renderImport$1(modelsImport));
378
455
  lines.push("");
456
+ if (resolver.options.lazySchemas && resolver.options.tsNamespaces) return renderLazyModels({
457
+ resolver,
458
+ tag,
459
+ zodSchemasData,
460
+ lines
461
+ });
379
462
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${getNamespaceName({
380
463
  type: "models",
381
464
  tag,
@@ -400,6 +483,50 @@ function generateModels({ resolver, data, tag }) {
400
483
  if (resolver.options.tsNamespaces) lines.push("}");
401
484
  return lines.join("\n").trimEnd() + "\n";
402
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
+ }
403
530
  function renderSchemaType(schema, resolver) {
404
531
  if (isReferenceObject(schema)) {
405
532
  const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
@@ -458,6 +585,20 @@ function renderModelsProxy({ resolver, data, tag }) {
458
585
  })}`;
459
586
  const inferredTypeNames = schemaNames.map((schemaName) => getZodSchemaInferedTypeName(schemaName, resolver.options));
460
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
+ }
461
602
  if (resolver.options.tsNamespaces) {
462
603
  const lines = [];
463
604
  lines.push(`import { ${commonNamespace} } from "${commonModelsPath}";`);
@@ -1,4 +1,4 @@
1
- const require_generate_utils = require("./generate.utils-D4eHo3wO.cjs");
1
+ const require_generate_utils = require("./generate.utils-BFeGvk98.cjs");
2
2
  let openapi_types = require("openapi-types");
3
3
  //#region src/generators/const/acl.const.ts
4
4
  const ACL_APP_ABILITY_FILE = {
@@ -2341,6 +2341,83 @@ function renderEndpointConfig(resolver, endpoint, modelNamespaceTag) {
2341
2341
  return lines.join("\n ");
2342
2342
  }
2343
2343
  //#endregion
2344
+ //#region src/generators/utils/generate/generate.lazy.utils.ts
2345
+ const ONCE_HELPER_LINES = [
2346
+ "const once = <T>(create: () => T) => {",
2347
+ " let value: T | undefined;",
2348
+ " return () => (value ??= create());",
2349
+ "};"
2350
+ ];
2351
+ const isIdentifierChar = (char) => /[A-Za-z0-9_$]/.test(char);
2352
+ const findLiteralEnd = (code, start, quote) => {
2353
+ let index = start + 1;
2354
+ while (index < code.length) {
2355
+ const char = code[index];
2356
+ if (char === "\\") {
2357
+ index += 2;
2358
+ continue;
2359
+ }
2360
+ index += 1;
2361
+ if (char === quote) break;
2362
+ }
2363
+ return Math.min(index, code.length);
2364
+ };
2365
+ const findRegexEnd = (code, start) => {
2366
+ let escaped = false;
2367
+ let characterClass = false;
2368
+ for (let index = start + 1; index < code.length; index += 1) {
2369
+ const char = code[index];
2370
+ if (escaped) {
2371
+ escaped = false;
2372
+ continue;
2373
+ }
2374
+ if (char === "\\") {
2375
+ escaped = true;
2376
+ continue;
2377
+ }
2378
+ if (char === "[") characterClass = true;
2379
+ if (char === "]") characterClass = false;
2380
+ if (char === "/" && !characterClass) return index + 1;
2381
+ }
2382
+ return code.length;
2383
+ };
2384
+ /**
2385
+ * Rewrites bare references to sibling schemas (`PetSchema`) into factory calls (`PetSchema()`).
2386
+ * Member accesses (`CommonModels.PetSchema`, `.enum`), object keys and literal values are left alone.
2387
+ */
2388
+ function callLazySchemaReferences(code, schemaNames) {
2389
+ let output = "";
2390
+ let index = 0;
2391
+ while (index < code.length) {
2392
+ const char = code[index];
2393
+ if (char === "\"" || char === "'" || char === "`") {
2394
+ const end = findLiteralEnd(code, index, char);
2395
+ output += code.slice(index, end);
2396
+ index = end;
2397
+ continue;
2398
+ }
2399
+ if (char === "/" && output.trimEnd().endsWith(".regex(")) {
2400
+ const end = findRegexEnd(code, index);
2401
+ output += code.slice(index, end);
2402
+ index = end;
2403
+ continue;
2404
+ }
2405
+ if (isIdentifierChar(char)) {
2406
+ let end = index + 1;
2407
+ while (end < code.length && isIdentifierChar(code[end])) end += 1;
2408
+ const identifier = code.slice(index, end);
2409
+ const isMemberAccess = output.endsWith(".");
2410
+ const isObjectKey = code.slice(end).trimStart().startsWith(":");
2411
+ output += schemaNames.has(identifier) && !isMemberAccess && !isObjectKey ? `${identifier}()` : identifier;
2412
+ index = end;
2413
+ continue;
2414
+ }
2415
+ output += char;
2416
+ index += 1;
2417
+ }
2418
+ return output;
2419
+ }
2420
+ //#endregion
2344
2421
  //#region src/generators/generate/generateModels.ts
2345
2422
  function generateModels({ resolver, data, tag }) {
2346
2423
  const nativeContent = resolver.getNativeRenderedModels?.(tag);
@@ -2376,6 +2453,12 @@ function generateModels({ resolver, data, tag }) {
2376
2453
  lines.push(renderImport$1(require_generate_utils.ZOD_IMPORT));
2377
2454
  for (const modelsImport of modelsImports) lines.push(renderImport$1(modelsImport));
2378
2455
  lines.push("");
2456
+ if (resolver.options.lazySchemas && resolver.options.tsNamespaces) return renderLazyModels({
2457
+ resolver,
2458
+ tag,
2459
+ zodSchemasData,
2460
+ lines
2461
+ });
2379
2462
  if (resolver.options.tsNamespaces) lines.push(`export namespace ${require_generate_utils.getNamespaceName({
2380
2463
  type: "models",
2381
2464
  tag,
@@ -2400,6 +2483,50 @@ function generateModels({ resolver, data, tag }) {
2400
2483
  if (resolver.options.tsNamespaces) lines.push("}");
2401
2484
  return lines.join("\n").trimEnd() + "\n";
2402
2485
  }
2486
+ function renderLazyModels({ resolver, tag, zodSchemasData, lines }) {
2487
+ const namespace = require_generate_utils.getNamespaceName({
2488
+ type: "models",
2489
+ tag,
2490
+ options: resolver.options
2491
+ });
2492
+ const schemaNames = new Set(Object.keys(zodSchemasData));
2493
+ const members = [];
2494
+ const types = [];
2495
+ lines.push(...ONCE_HELPER_LINES, "");
2496
+ for (const [name, zodSchema] of Object.entries(zodSchemasData)) {
2497
+ const inferredTypeName = require_generate_utils.getZodSchemaInferedTypeName(name, resolver.options);
2498
+ const typeAnnotation = zodSchema.isCircular ? `: () => z.ZodObject<z.ZodRawShape> & z.ZodType<${namespace}.${inferredTypeName}>` : "";
2499
+ const schemaCode = resolver.options.compileSchemas && !zodSchema.isCircular ? `z.compile(${zodSchema.code})` : zodSchema.code;
2500
+ lines.push(`const ${name}${typeAnnotation} = once(() => ${callLazySchemaReferences(schemaCode, schemaNames)});`);
2501
+ members.push(...indent(renderModelJsDocs({
2502
+ name,
2503
+ zodSchema,
2504
+ tag,
2505
+ resolver
2506
+ }).split("\n")));
2507
+ members.push(...renderLazyMember(name, `${name}()`));
2508
+ if (zodSchema.isCircular && zodSchema.schemaObj) types.push(` export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
2509
+ else types.push(` export type ${inferredTypeName} = z.infer<typeof ${namespace}.${name}>;`);
2510
+ if (zodSchema.isEnum) {
2511
+ lines.push(`const ${inferredTypeName} = once(() => ${name}().enum);`);
2512
+ members.push(...renderLazyMember(inferredTypeName, `${inferredTypeName}()`));
2513
+ }
2514
+ }
2515
+ lines.push("");
2516
+ lines.push(`export const ${namespace} = {`, ...members, "};");
2517
+ lines.push(`export declare namespace ${namespace} {`, ...types, "}");
2518
+ return lines.join("\n") + "\n";
2519
+ }
2520
+ function renderLazyMember(name, value) {
2521
+ return [
2522
+ ` get ${name}() {`,
2523
+ ` return ${value};`,
2524
+ ` },`
2525
+ ];
2526
+ }
2527
+ function indent(lines) {
2528
+ return lines.map((line) => ` ${line}`);
2529
+ }
2403
2530
  function renderSchemaType(schema, resolver) {
2404
2531
  if (require_generate_utils.isReferenceObject(schema)) {
2405
2532
  const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
@@ -2458,6 +2585,20 @@ function renderModelsProxy({ resolver, data, tag }) {
2458
2585
  })}`;
2459
2586
  const inferredTypeNames = schemaNames.map((schemaName) => require_generate_utils.getZodSchemaInferedTypeName(schemaName, resolver.options));
2460
2587
  const enumInferredTypeNames = schemaNames.filter((schemaName) => require_generate_utils.isEnumZodSchema(commonZodSchemas[schemaName] ?? "")).map((schemaName) => require_generate_utils.getZodSchemaInferedTypeName(schemaName, resolver.options));
2588
+ if (resolver.options.tsNamespaces && resolver.options.lazySchemas) {
2589
+ const lines = [];
2590
+ lines.push(`import { ${commonNamespace} } from "${commonModelsPath}";`);
2591
+ lines.push("");
2592
+ lines.push(`export const ${modelsNamespace} = {`);
2593
+ for (const schemaName of schemaNames) lines.push(...renderLazyMember(schemaName, `${commonNamespace}.${schemaName}`));
2594
+ for (const enumName of enumInferredTypeNames) lines.push(...renderLazyMember(enumName, `${commonNamespace}.${enumName}`));
2595
+ lines.push("};");
2596
+ lines.push(`export declare namespace ${modelsNamespace} {`);
2597
+ for (const typeName of inferredTypeNames) lines.push(` export type ${typeName} = ${commonNamespace}.${typeName};`);
2598
+ lines.push("}");
2599
+ lines.push("");
2600
+ return lines.join("\n");
2601
+ }
2461
2602
  if (resolver.options.tsNamespaces) {
2462
2603
  const lines = [];
2463
2604
  lines.push(`import { ${commonNamespace} } from "${commonModelsPath}";`);
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-BV720uS2.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-B7-eMFcv.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 { 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";
1
+ import { r as getQueryName, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-B7VWwIbb.mjs";
2
+ import { a as isQuery, i as isMutation, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-C0iehdg8.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-LDL6Lbgl.mjs";
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
5
5
  async function getMetadataFromOpenAPIDoc(openApiDoc, options) {
6
6
  const { resolver, data } = await getDataFromOpenAPIDoc(openApiDoc, options);
@@ -1,4 +1,4 @@
1
- import { $ as getParamZodSchemaName, At as pathParamToVariableName, Bt as ALLOWED_PATH_IN, Ct as isErrorStatus, Dt as isPathExcluded, Et as isParamMediaTypeAllowed, Ft as inferRequiredSchema, Gt as ENUM_SCHEMA, Ht as BLOB_SCHEMA, It as isArraySchemaObject, J as getUniqueArray, Jt as STRING_SCHEMA, Kt as INT_SCHEMA, Lt as isReferenceObject, Mt as replaceHyphenatedPath, Nt as unwrapQuotesIfNeeded, Ot as isPrimitiveType, Pt as wrapWithQuotesIfNeeded, Q as getEnumZodSchemaName, Rt as isSchemaObject, St as getSchemaRef, Tt as isMediaTypeAllowed, Ut as DATETIME_SCHEMA, Vt as ANY_SCHEMA, Wt as EMAIL_SCHEMA, X as invalidVariableNameCharactersToCamel, Xt as UUID_SCHEMA, Yt as URL_SCHEMA, Z as getBodyZodSchemaName, Zt as VOID_SCHEMA, _n as Profiler, _t as getNamespaceName, bt as getParameterEnumNames, cn as getEndpointTag, et as getResponseZodSchemaName, fn as capitalize, gn as snakeToCamel, hn as removeWord, in as JSON_APPLICATION_FORMAT, it as isNamedZodSchema, jt as pathToVariableName, kt as isSortingParameterObject, ln as getOperationTag, m as mapEndpointParamsToFunctionParams, mn as getMostCommonAdjacentCombinationSplit, nt as getZodSchemaOperationName, pn as decapitalize, q as iterateSchema, qt as NUMBER_SCHEMA, rn as BODY_PARAMETER_NAME, s as pick, sn as formatTag, tt as getZodSchemaName, un as isTagIncluded, vt as autocorrectRef, wt as isMainResponseStatus, xt as getSchemaNameByRef, yt as escapeControlCharacters, zt as ALLOWED_METHODS } from "./generate.runner-BMqvEp4L.mjs";
1
+ import { $ as getParamZodSchemaName, At as pathParamToVariableName, Bt as ALLOWED_PATH_IN, Ct as isErrorStatus, Dt as isPathExcluded, Et as isParamMediaTypeAllowed, Ft as inferRequiredSchema, Gt as ENUM_SCHEMA, Ht as BLOB_SCHEMA, It as isArraySchemaObject, J as getUniqueArray, Jt as STRING_SCHEMA, Kt as INT_SCHEMA, Lt as isReferenceObject, Mt as replaceHyphenatedPath, Nt as unwrapQuotesIfNeeded, Ot as isPrimitiveType, Pt as wrapWithQuotesIfNeeded, Q as getEnumZodSchemaName, Rt as isSchemaObject, St as getSchemaRef, Tt as isMediaTypeAllowed, Ut as DATETIME_SCHEMA, Vt as ANY_SCHEMA, Wt as EMAIL_SCHEMA, X as invalidVariableNameCharactersToCamel, Xt as UUID_SCHEMA, Yt as URL_SCHEMA, Z as getBodyZodSchemaName, Zt as VOID_SCHEMA, _n as Profiler, _t as getNamespaceName, bt as getParameterEnumNames, cn as getEndpointTag, et as getResponseZodSchemaName, fn as capitalize, gn as snakeToCamel, hn as removeWord, in as JSON_APPLICATION_FORMAT, it as isNamedZodSchema, jt as pathToVariableName, kt as isSortingParameterObject, ln as getOperationTag, m as mapEndpointParamsToFunctionParams, mn as getMostCommonAdjacentCombinationSplit, nt as getZodSchemaOperationName, pn as decapitalize, q as iterateSchema, qt as NUMBER_SCHEMA, rn as BODY_PARAMETER_NAME, s as pick, sn as formatTag, tt as getZodSchemaName, un as isTagIncluded, vt as autocorrectRef, wt as isMainResponseStatus, xt as getSchemaNameByRef, yt as escapeControlCharacters, zt as ALLOWED_METHODS } from "./generate.runner-LDL6Lbgl.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
3
  //#region src/generators/const/validation.const.ts
4
4
  const HTTP_STATUS_CODES = {
package/dist/index.d.mts CHANGED
@@ -3,10 +3,10 @@ import { a as ErrorHandler, c as GeneralErrorCodes, i as ErrorEntry, l as Shared
3
3
  import { n as AuthGuardProps, r as AuthContext, t as AuthGuard } from "./AuthGuard-GbtTDXs0.mjs";
4
4
  import { a as RestClient, i as Response, n as RequestConfig, o as RestInterceptor, r as RequestInfo, t as RestClient$1 } from "./rest-client-CbS77dei.mjs";
5
5
  import { n as useWorkspaceContext, r as OpenApiRouter, t as OpenApiWorkspaceContext } from "./workspace.context-isVY9ves.mjs";
6
- import { a as MutationEffectsTypes, c as RegisteredQueryModule, i as MutationEffectsOf, n as InvalidationMapFunc, o as OpenApiQueryConfig, r as MergedMutationVariables, s as QueryModule, t as InvalidationMap } from "./queryConfig.context-BbLtDfIH.mjs";
6
+ import { a as MergedMutationVariables, c as OpenApiQueryConfig, i as MergedMutationValues, l as QueryModule, n as InvalidationMapFunc, o as MutationEffectsOf, r as MergedMutationData, s as MutationEffectsTypes, t as InvalidationMap, u as RegisteredQueryModule } from "./queryConfig.context-DwVQWbtL.mjs";
7
7
  import { t as RestUtils } from "./rest.utils-DpiFIdhF.mjs";
8
- import { t as OpenAPICodegenConfig } from "./config-BSYiW3xV.mjs";
8
+ import { t as OpenAPICodegenConfig } from "./config-D8ANLlqk.mjs";
9
9
  import { d as TransportResponse, l as TransportRequest, n as HttpError, p as UploadProgress, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
10
10
  import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-DZxdDcpz.mjs";
11
- import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-CmGB4BOV.mjs";
12
- export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type ErrorRethrower, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsOptions, type MutationEffectsTypes, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequestConfig as NativeRequestConfig, type TransportResponse as NativeResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RegisteredQueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, type TranslateFunction, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
11
+ import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-I4y5WUkj.mjs";
12
+ export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type ErrorRethrower, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MergedMutationData, type MergedMutationValues, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsOptions, type MutationEffectsTypes, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequestConfig as NativeRequestConfig, type TransportResponse as NativeResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RegisteredQueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, type TranslateFunction, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
package/dist/metro.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generate_utils = require("./generate.utils-D4eHo3wO.cjs");
2
+ const require_generate_utils = require("./generate.utils-BFeGvk98.cjs");
3
3
  let fs = require("fs");
4
4
  fs = require_generate_utils.__toESM(fs, 1);
5
5
  let path = require("path");
@@ -15,6 +15,7 @@ function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, in
15
15
  workspaceContext: workspaceContext?.split(",")
16
16
  });
17
17
  if (resolvedConfig.modelsInCommon && resolvedConfig.modelsInModules) throw new Error("modelsInCommon and modelsInModules cannot both be enabled");
18
+ if (resolvedConfig.lazySchemas && !resolvedConfig.tsNamespaces) throw new Error("lazySchemas requires tsNamespaces");
18
19
  resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
19
20
  resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
20
21
  return resolvedConfig;
@@ -102,7 +103,7 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
102
103
  const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
103
104
  if (nativeFiles) return nativeFiles;
104
105
  }
105
- const { generateCodeFromOpenAPIDoc } = await Promise.resolve().then(() => require("./generateCodeFromOpenAPIDoc-DRLE112u.cjs"));
106
+ const { generateCodeFromOpenAPIDoc } = await Promise.resolve().then(() => require("./generateCodeFromOpenAPIDoc-CpAdx6I3.cjs"));
106
107
  return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
107
108
  source: nativeInput.source,
108
109
  yaml: nativeInput.yaml
package/dist/metro.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { r as GenerateFileFormatter } from "./options-BV720uS2.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-BSYiW3xV.mjs";
3
- import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DEtp4qCv.mjs";
1
+ import { r as GenerateFileFormatter } from "./options-B7-eMFcv.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-D8ANLlqk.mjs";
3
+ import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DES1kzvS.mjs";
4
4
  import { IncomingMessage, ServerResponse } from "http";
5
5
  //#region src/metro/openapi-codegen.plugin.d.ts
6
6
  type OpenApiCodegenMetroConfig = OpenAPICodegenConfig & {
package/dist/metro.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-R_Dnb1mt.mjs";
1
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-CmW9oZdT.mjs";
2
2
  import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-DPUNTduQ.mjs";
3
3
  import fs from "fs";
4
4
  import path from "path";
@@ -1,4 +1,4 @@
1
- import { _n as Profiler, n as runGenerate } from "./generate.runner-BMqvEp4L.mjs";
1
+ import { _n as Profiler, n as runGenerate } from "./generate.runner-LDL6Lbgl.mjs";
2
2
  import path from "path";
3
3
  //#region src/plugins/openapi-codegen.runner.ts
4
4
  function createOpenApiCodegenRunner(config, options = {}) {
@@ -1,4 +1,4 @@
1
- import { t as OpenAPICodegenConfig } from "./config-BSYiW3xV.mjs";
1
+ import { t as OpenAPICodegenConfig } from "./config-D8ANLlqk.mjs";
2
2
  //#region src/tiny/openapi.d.ts
3
3
  interface GenerateOpenApiFileOptions {
4
4
  argv?: readonly string[];
@@ -16,6 +16,8 @@ type GenerateFileFormatter = (file: GenerateFileData) => string | Promise<string
16
16
  interface ZodGenerateOptions {
17
17
  /** Eagerly compile non-recursive schemas. Defaults to false to avoid startup work. */
18
18
  compileSchemas?: boolean;
19
+ /** Build namespace model schemas on first access instead of at import. Requires tsNamespaces. */
20
+ lazySchemas?: boolean;
19
21
  schemaSuffix: string;
20
22
  enumSuffix: string;
21
23
  modelsInCommon?: boolean;
package/dist/query.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as MutationEffectsTypes, c as RegisteredQueryModule, i as MutationEffectsOf, n as InvalidationMapFunc, o as OpenApiQueryConfig, r as MergedMutationVariables, s as QueryModule, t as InvalidationMap } from "./queryConfig.context-BbLtDfIH.mjs";
2
- import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-CmGB4BOV.mjs";
3
- export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, type InvalidationMap, type InvalidationMapFunc, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsOptions, type MutationEffectsTypes, OpenApiQueryConfig, type QueryModule, type RegisteredQueryModule, useMutationEffects };
1
+ import { a as MergedMutationVariables, c as OpenApiQueryConfig, i as MergedMutationValues, l as QueryModule, n as InvalidationMapFunc, o as MutationEffectsOf, r as MergedMutationData, s as MutationEffectsTypes, t as InvalidationMap, u as RegisteredQueryModule } from "./queryConfig.context-DwVQWbtL.mjs";
2
+ import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-I4y5WUkj.mjs";
3
+ export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, type InvalidationMap, type InvalidationMapFunc, type MergedMutationData, type MergedMutationValues, type MergedMutationVariables, type MutationEffectsOf, type MutationEffectsOptions, type MutationEffectsTypes, OpenApiQueryConfig, type QueryModule, type RegisteredQueryModule, useMutationEffects };
@@ -22,13 +22,18 @@ type IsUnion<T, TAll = T> = T extends unknown ? ([TAll] extends [T] ? false : tr
22
22
  type MergeableMembers<T> = T extends readonly unknown[] | ((...args: never) => unknown) | Date ? never : ObjectMembers<T>;
23
23
  type MergedValue<T> = true extends IsUnion<MergeableMembers<T>> ? MergedObjects<MergeableMembers<T>> | Exclude<T, MergeableMembers<T>> : T;
24
24
  type MergedObjects<T> = { [K in Extract<keyof T, PropertyKey>]: MergedValue<ValueOfUnion<T, K>>; } & { [K in Exclude<KeysOfUnion<T>, keyof T>]?: MergedValue<ValueOfUnion<T, K>>; };
25
+ type VoidAsUndefined<T> = [void] extends [T] ? Exclude<T, void> | undefined : T;
25
26
  /**
26
- * The variables of a module's mutations as one object: keys some mutations lack become optional, at any
27
- * depth (e.g. fields of request bodies only some mutations send). Mutations without variables (`void`)
28
- * stay in the union, as their callbacks receive `undefined`.
27
+ * A union of a module's mutation values as one object: keys some mutations lack become optional, at any
28
+ * depth (e.g. fields of request bodies only some mutations send). `void` becomes `undefined`, which is
29
+ * what callbacks receive for mutations without one.
29
30
  */
30
- type MergedMutationVariables<T> = [ObjectMembers<T>] extends [never] ? T : MergedObjects<ObjectMembers<T>> | Exclude<T, object>;
31
- type InvalidationMapFuncFor<T> = InvalidationMapFunc<T extends MutationEffectsTypes ? T["data"] : never, MergedMutationVariables<T extends MutationEffectsTypes ? T["variables"] : never>>;
31
+ type MergedMutationValues<T> = [ObjectMembers<T>] extends [never] ? VoidAsUndefined<T> : MergedObjects<ObjectMembers<T>> | VoidAsUndefined<Exclude<T, object>>;
32
+ /** The variables of a module's mutations as one object; see `MergedMutationValues`. */
33
+ type MergedMutationVariables<T> = MergedMutationValues<T>;
34
+ /** The responses of a module's mutations as one object; see `MergedMutationValues`. */
35
+ type MergedMutationData<T> = MergedMutationValues<T>;
36
+ type InvalidationMapFuncFor<T> = InvalidationMapFunc<MergedMutationData<T extends MutationEffectsTypes ? T["data"] : never>, MergedMutationVariables<T extends MutationEffectsTypes ? T["variables"] : never>>;
32
37
  declare global {
33
38
  /**
34
39
  * Mutation types per module. The generated `queryModules.ts` extends it with `QueryModuleMutations`, so
@@ -63,4 +68,4 @@ declare namespace OpenApiQueryConfig {
63
68
  export {};
64
69
  }
65
70
  //#endregion
66
- export { MutationEffectsTypes as a, RegisteredQueryModule as c, MutationEffectsOf as i, InvalidationMapFunc as n, OpenApiQueryConfig as o, MergedMutationVariables as r, QueryModule as s, InvalidationMap as t };
71
+ export { MergedMutationVariables as a, OpenApiQueryConfig as c, MergedMutationValues as i, QueryModule as l, InvalidationMapFunc as n, MutationEffectsOf as o, MergedMutationData as r, MutationEffectsTypes as s, InvalidationMap as t, RegisteredQueryModule as u };
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
- import { c as VALIDATION_ERROR_TYPE_TITLE, o as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BqEeVt1w.mjs";
3
- import { C as getTagFileName, _n as Profiler, a as resolveConfig, n as runGenerate, o as getOutputFileName, t as getOpenApiDoc } from "./generate.runner-BMqvEp4L.mjs";
2
+ import { c as VALIDATION_ERROR_TYPE_TITLE, o as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-C0iehdg8.mjs";
3
+ import { C as getTagFileName, _n as Profiler, a as resolveConfig, n as runGenerate, o as getOutputFileName, t as getOpenApiDoc } from "./generate.runner-LDL6Lbgl.mjs";
4
4
  import yargs from "yargs";
5
5
  import { hideBin } from "yargs/helpers";
6
6
  import { styleText } from "node:util";
@@ -31,7 +31,7 @@ function logBanner(message) {
31
31
  * Fetch the version from package.json
32
32
  */
33
33
  function getVersion() {
34
- return "4.0.0-rc.4";
34
+ return "4.0.0-rc.5";
35
35
  }
36
36
  //#endregion
37
37
  //#region src/helpers/yargs.helper.ts
@@ -268,6 +268,7 @@ var GenerateOptions = class {
268
268
  excludeRedundantZodSchemas;
269
269
  importPath;
270
270
  compileSchemas;
271
+ lazySchemas;
271
272
  extractEnums;
272
273
  modelsInCommon;
273
274
  modelsInModules;
@@ -330,6 +331,10 @@ __decorate([YargOption({
330
331
  envAlias: "compileSchemas",
331
332
  type: "boolean"
332
333
  }), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "compileSchemas", void 0);
334
+ __decorate([YargOption({
335
+ envAlias: "lazySchemas",
336
+ type: "boolean"
337
+ }), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "lazySchemas", void 0);
333
338
  __decorate([YargOption({
334
339
  envAlias: "extractEnums",
335
340
  type: "boolean"
package/dist/tiny.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as getModuleOpenApiTag, A as collectApiModelSchemaExports, At as toOpenAPI30Document, B as collectReachableModelSchemas, C as applyEnumExtensions, Ct as procedureSchemaName, D as applyRobodevModuleExtensions, Dt as schemaExportName, E as applyParameterExtensions, Et as schemaComponentRef, F as collectExtraSchemas, G as findComponentEnumNames, H as compactTagName, I as collectModelSchemaExports, J as generateOpenApiFile, K as findEnumNames, L as collectModuleModelSchemaExports, M as collectContractSchemas, Mt as toOpenAPIAclRule, N as collectDbTableModelSchemaExport, Nt as toPascalCase, O as applyRobodevUserRolesExtension, Ot as sharedSchemaExportName, P as collectDbTableModelSchemaExports, Pt as visitZodSchema, Q as getModuleOpenApiController, R as collectOperationMeta, S as addContractSchema, St as operationKey, T as applyPaginatedItemSchemas, Tt as routeHasPathParameters, U as createModelSchemaNameGetter, V as collectSchemaRegistryRoots, W as defineOpenApiSchemas, X as getContractProcedureData, Y as getComponentSchemas, Z as getDerivedOperationId, _ as OpenApiSchemaRegistry, _t as namedControllerActionSchema, a as isTinyOpenApiFakeMode, at as getProcedureInputSchemaRole, b as TinyOpenApiUserRole, bt as namedOpenApiResponseSchema, c as AnyContractRouter, ct as isContractProcedure, d as GenerateOpenApiFile, dt as isObject, et as getObjectPropertySchema, f as GenerateOpenApiFileOptions, ft as isProcedureMeta, g as JsonObject, gt as namedControllerActionInputDtoSchema, h as GenerateTinyOpenApiFileOptions, ht as modelSchemaNameEntries, i as getLocalInputPath, it as getPaginatedItemSchema, j as collectContractSchemaRoots, jt as toOpenAPI30Schema, k as asStringArray, kt as stripNoContentResponseBodies, l as AnySchema, lt as isNullSchema, m as GenerateOpenApiSpec, mt as modelSchemaExportName, nt as getOperationAction, o as normalizeWatchFolders, ot as getRobodevModuleRoles, p as GenerateOpenApiFileResult, pt as isZodSchema, q as generateORPCOpenAPISpec, r as createTinyOpenApiSourceRunner, rt as getOperationController, s as AclRule, st as getStringEnumValues, t as TinyOpenApiSourceRunnerConfig, tt as getOpenApiSchemaName, u as GenerateORPCOpenAPISpecOptions, ut as isNullableOnlySchema, v as ProcedureMeta, vt as namedOpenApiOutputSchema, w as applyOperationMeta, wt as resolveOpenApiOutputPath, x as ZodSchema, xt as namedOpenApiSchema, y as TinyOpenApiModule, yt as namedOpenApiRequestSchema, z as collectOperationTags } from "./openapi-source.runner-DEtp4qCv.mjs";
1
+ import { $ as getModuleOpenApiTag, A as collectApiModelSchemaExports, At as toOpenAPI30Document, B as collectReachableModelSchemas, C as applyEnumExtensions, Ct as procedureSchemaName, D as applyRobodevModuleExtensions, Dt as schemaExportName, E as applyParameterExtensions, Et as schemaComponentRef, F as collectExtraSchemas, G as findComponentEnumNames, H as compactTagName, I as collectModelSchemaExports, J as generateOpenApiFile, K as findEnumNames, L as collectModuleModelSchemaExports, M as collectContractSchemas, Mt as toOpenAPIAclRule, N as collectDbTableModelSchemaExport, Nt as toPascalCase, O as applyRobodevUserRolesExtension, Ot as sharedSchemaExportName, P as collectDbTableModelSchemaExports, Pt as visitZodSchema, Q as getModuleOpenApiController, R as collectOperationMeta, S as addContractSchema, St as operationKey, T as applyPaginatedItemSchemas, Tt as routeHasPathParameters, U as createModelSchemaNameGetter, V as collectSchemaRegistryRoots, W as defineOpenApiSchemas, X as getContractProcedureData, Y as getComponentSchemas, Z as getDerivedOperationId, _ as OpenApiSchemaRegistry, _t as namedControllerActionSchema, a as isTinyOpenApiFakeMode, at as getProcedureInputSchemaRole, b as TinyOpenApiUserRole, bt as namedOpenApiResponseSchema, c as AnyContractRouter, ct as isContractProcedure, d as GenerateOpenApiFile, dt as isObject, et as getObjectPropertySchema, f as GenerateOpenApiFileOptions, ft as isProcedureMeta, g as JsonObject, gt as namedControllerActionInputDtoSchema, h as GenerateTinyOpenApiFileOptions, ht as modelSchemaNameEntries, i as getLocalInputPath, it as getPaginatedItemSchema, j as collectContractSchemaRoots, jt as toOpenAPI30Schema, k as asStringArray, kt as stripNoContentResponseBodies, l as AnySchema, lt as isNullSchema, m as GenerateOpenApiSpec, mt as modelSchemaExportName, nt as getOperationAction, o as normalizeWatchFolders, ot as getRobodevModuleRoles, p as GenerateOpenApiFileResult, pt as isZodSchema, q as generateORPCOpenAPISpec, r as createTinyOpenApiSourceRunner, rt as getOperationController, s as AclRule, st as getStringEnumValues, t as TinyOpenApiSourceRunnerConfig, tt as getOpenApiSchemaName, u as GenerateORPCOpenAPISpecOptions, ut as isNullableOnlySchema, v as ProcedureMeta, vt as namedOpenApiOutputSchema, w as applyOperationMeta, wt as resolveOpenApiOutputPath, x as ZodSchema, xt as namedOpenApiSchema, y as TinyOpenApiModule, yt as namedOpenApiRequestSchema, z as collectOperationTags } from "./openapi-source.runner-DES1kzvS.mjs";
2
2
  export { AclRule, AnyContractRouter, AnySchema, GenerateORPCOpenAPISpecOptions, GenerateOpenApiFile, GenerateOpenApiFileOptions, GenerateOpenApiFileResult, GenerateOpenApiSpec, GenerateTinyOpenApiFileOptions, JsonObject, OpenApiSchemaRegistry, ProcedureMeta, TinyOpenApiModule, type TinyOpenApiSourceRunnerConfig, TinyOpenApiUserRole, ZodSchema, addContractSchema, applyEnumExtensions, applyOperationMeta, applyPaginatedItemSchemas, applyParameterExtensions, applyRobodevModuleExtensions, applyRobodevUserRolesExtension, asStringArray, collectApiModelSchemaExports, collectContractSchemaRoots, collectContractSchemas, collectDbTableModelSchemaExport, collectDbTableModelSchemaExports, collectExtraSchemas, collectModelSchemaExports, collectModuleModelSchemaExports, collectOperationMeta, collectOperationTags, collectReachableModelSchemas, collectSchemaRegistryRoots, compactTagName, createModelSchemaNameGetter, createTinyOpenApiSourceRunner, defineOpenApiSchemas, findComponentEnumNames, findEnumNames, generateORPCOpenAPISpec, generateOpenApiFile, getComponentSchemas, getContractProcedureData, getDerivedOperationId, getModuleOpenApiController, getModuleOpenApiTag, getObjectPropertySchema, getOpenApiSchemaName, getOperationAction, getOperationController, getPaginatedItemSchema, getProcedureInputSchemaRole, getRobodevModuleRoles, getStringEnumValues, getLocalInputPath as getTinyOpenApiLocalInputPath, isContractProcedure, isNullSchema, isNullableOnlySchema, isObject, isProcedureMeta, isTinyOpenApiFakeMode, isZodSchema, modelSchemaExportName, modelSchemaNameEntries, namedControllerActionInputDtoSchema, namedControllerActionSchema, namedOpenApiOutputSchema, namedOpenApiRequestSchema, namedOpenApiResponseSchema, namedOpenApiSchema, normalizeWatchFolders as normalizeTinyOpenApiWatchFolders, operationKey, procedureSchemaName, resolveOpenApiOutputPath, routeHasPathParameters, schemaComponentRef, schemaExportName, sharedSchemaExportName, stripNoContentResponseBodies, toOpenAPI30Document, toOpenAPI30Schema, toOpenAPIAclRule, toPascalCase, visitZodSchema };
@@ -1,5 +1,5 @@
1
1
  import { c as GeneralErrorCodes, t as ApplicationException } from "./error-handling-BpAQHWrU.mjs";
2
- import { s as QueryModule, t as InvalidationMap } from "./queryConfig.context-BbLtDfIH.mjs";
2
+ import { l as QueryModule, t as InvalidationMap } from "./queryConfig.context-DwVQWbtL.mjs";
3
3
  import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
4
4
  //#region src/lib/react-query.types.d.ts
5
5
  type Function = (...args: never) => unknown;
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { r as GenerateFileFormatter } from "./options-BV720uS2.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-BSYiW3xV.mjs";
3
- import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DEtp4qCv.mjs";
1
+ import { r as GenerateFileFormatter } from "./options-B7-eMFcv.mjs";
2
+ import { t as OpenAPICodegenConfig } from "./config-D8ANLlqk.mjs";
3
+ import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DES1kzvS.mjs";
4
4
  import { Plugin, PluginOption } from "vite";
5
5
  //#region src/plugins/openapi-codegen.runner.d.ts
6
6
  type OpenApiCodegenPluginConfig = OpenAPICodegenConfig & {
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-R_Dnb1mt.mjs";
1
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-CmW9oZdT.mjs";
2
2
  import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-DPUNTduQ.mjs";
3
3
  import path from "path";
4
4
  //#region src/vite/openapi-codegen.plugin.ts
package/package.json CHANGED
@@ -128,7 +128,7 @@
128
128
  "@casl/ability": "6.8.0",
129
129
  "@casl/react": "5.0.1",
130
130
  "@tanstack/react-query": "~5.90.21",
131
- "@types/bun": "1.4.3",
131
+ "@types/bun": "1.4.4",
132
132
  "@types/node": "^25.3.0",
133
133
  "@types/prompt-sync": "^4.2.3",
134
134
  "@types/react": "^19.2.14",
@@ -183,9 +183,9 @@
183
183
  }
184
184
  },
185
185
  "engines": {
186
- "bun": ">= 1.4.3",
186
+ "bun": ">= 1.4.4",
187
187
  "node": ">= 18"
188
188
  },
189
- "packageManager": "bun@1.4.3",
190
- "version": "4.0.0-rc.4"
189
+ "packageManager": "bun@1.4.4",
190
+ "version": "4.0.0-rc.5"
191
191
  }