@dudousxd/nestjs-codegen 0.5.1 → 0.5.2

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.
@@ -584,37 +584,28 @@ function buildProperty(prop, classFile, ctx) {
584
584
  const typeNode = prop.getTypeNode();
585
585
  const typeText = typeNode?.getText() ?? "unknown";
586
586
  const isArrayType = !!typeNode && import_ts_morph2.Node.isArrayTypeNode(typeNode);
587
+ const asField = (child) => applyPresence(
588
+ has("IsArray") || isArrayType ? { kind: "array", element: child } : child,
589
+ decorators
590
+ );
587
591
  const discriminator = resolveDiscriminator(dec("Type"));
588
592
  if (discriminator) {
589
593
  const options = discriminator.subTypes.map(
590
594
  (name) => buildNestedReference(name, classFile, ctx)
591
595
  );
592
- const unionNode = {
593
- kind: "union",
594
- options,
595
- discriminator: discriminator.property
596
- };
597
- const wrapArray = has("IsArray") || isArrayType;
598
- const node2 = wrapArray ? { kind: "array", element: unionNode } : unionNode;
599
- return applyPresence(node2, decorators);
596
+ return asField({ kind: "union", options, discriminator: discriminator.property });
600
597
  }
601
598
  const propTypeParam = singularClassName(typeText);
602
599
  if (propTypeParam && ctx.typeBindings.has(propTypeParam)) {
603
600
  const bound = ctx.typeBindings.get(propTypeParam);
604
- const childNode = buildNestedReference(bound, classFile, ctx);
605
- const wrapArray = has("IsArray") || isArrayType;
606
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
607
- return applyPresence(node2, decorators);
601
+ return asField(buildNestedReference(bound, classFile, ctx));
608
602
  }
609
603
  const typeRefName = resolveTypeFactoryName(dec("Type"));
610
604
  if (has("ValidateNested") || typeRefName) {
611
605
  const typeArgs = genericTypeArgNames(typeNode);
612
606
  const childName = typeRefName ?? singularClassName(typeText);
613
607
  if (childName) {
614
- const childNode = buildNestedReference(childName, classFile, ctx, typeArgs);
615
- const wrapArray = has("IsArray") || isArrayType;
616
- const node2 = wrapArray ? { kind: "array", element: childNode } : childNode;
617
- return applyPresence(node2, decorators);
608
+ return asField(buildNestedReference(childName, classFile, ctx, typeArgs));
618
609
  }
619
610
  }
620
611
  let base = baseFromType(typeText, isArrayType);