@pegasusheavy/nestjs-prisma-graphql 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/generate.js CHANGED
@@ -461,7 +461,7 @@ function getGraphqlImport(args) {
461
461
  case "Decimal": {
462
462
  return {
463
463
  name: "GraphQLDecimal",
464
- specifier: "prisma-graphql-type-decimal"
464
+ specifier: "graphql-scalars"
465
465
  };
466
466
  }
467
467
  case "Json": {
@@ -803,7 +803,11 @@ function inputType(args) {
803
803
  ]
804
804
  });
805
805
  if (graphqlType === "GraphQLDecimal") {
806
- importDeclarations.add("transformToDecimal", "prisma-graphql-type-decimal");
806
+ const decimalHelpersPath = relativePath(
807
+ sourceFile.getFilePath(),
808
+ `${output}/decimal-helpers.ts`
809
+ );
810
+ importDeclarations.add("transformToDecimal", decimalHelpersPath);
807
811
  importDeclarations.add("Transform", "class-transformer");
808
812
  importDeclarations.add("Type", "class-transformer");
809
813
  property.decorators.push(
@@ -2071,6 +2075,74 @@ export function validateRegistry(expectedTypes: string[]): void {
2071
2075
  sourceFile.addStatements(registryCode);
2072
2076
  }
2073
2077
 
2078
+ // src/handlers/decimal-helpers.ts
2079
+ function generateDecimalHelpers(args) {
2080
+ const { config, output, project } = args;
2081
+ const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
2082
+ const sourceFile = rootDirectory.createSourceFile(
2083
+ "decimal-helpers.ts",
2084
+ void 0,
2085
+ { overwrite: true }
2086
+ );
2087
+ const helpersCode = `/**
2088
+ * Decimal Helpers for Prisma GraphQL
2089
+ *
2090
+ * This module provides utilities for transforming Decimal values
2091
+ * between GraphQL and Prisma, compatible with Prisma 7+.
2092
+ *
2093
+ * These functions replace the prisma-graphql-type-decimal package
2094
+ * which is incompatible with Prisma 7's new client structure.
2095
+ */
2096
+
2097
+ import Decimal from 'decimal.js';
2098
+
2099
+ /**
2100
+ * Reconstruct a Decimal from a serialized object.
2101
+ * Prisma serializes Decimals as objects with d, e, s properties.
2102
+ */
2103
+ function createDecimalFromObject(object: { d: number[]; e: number; s: number }): Decimal {
2104
+ return Object.create(Decimal.prototype, {
2105
+ d: { value: object.d },
2106
+ e: { value: object.e },
2107
+ s: { value: object.s },
2108
+ });
2109
+ }
2110
+
2111
+ /**
2112
+ * Transform input values to Decimal instances.
2113
+ * Used as a class-transformer Transform decorator argument.
2114
+ *
2115
+ * @param params - The transform parameters from class-transformer
2116
+ * @returns The transformed Decimal or array of Decimals
2117
+ */
2118
+ export function transformToDecimal({ value }: { value: unknown }): Decimal | Decimal[] | null | undefined {
2119
+ if (value == null) return value as null | undefined;
2120
+
2121
+ if (Array.isArray(value)) {
2122
+ return value.map((v) => {
2123
+ if (v instanceof Decimal) return v;
2124
+ if (typeof v === 'object' && v !== null && 'd' in v && 'e' in v && 's' in v) {
2125
+ return createDecimalFromObject(v as { d: number[]; e: number; s: number });
2126
+ }
2127
+ return new Decimal(v as string | number);
2128
+ });
2129
+ }
2130
+
2131
+ if (value instanceof Decimal) return value;
2132
+ if (typeof value === 'object' && value !== null && 'd' in value && 'e' in value && 's' in value) {
2133
+ return createDecimalFromObject(value as { d: number[]; e: number; s: number });
2134
+ }
2135
+ return new Decimal(value as string | number);
2136
+ }
2137
+
2138
+ /**
2139
+ * Re-export Decimal class for convenience
2140
+ */
2141
+ export { Decimal };
2142
+ `;
2143
+ sourceFile.addStatements(helpersCode);
2144
+ }
2145
+
2074
2146
  // src/handlers/warning.ts
2075
2147
  function warning(message) {
2076
2148
  if (Array.isArray(message)) {
@@ -2502,6 +2574,7 @@ async function generate(args) {
2502
2574
  if (config.esmCompatible) {
2503
2575
  generateTypeRegistry(eventArguments);
2504
2576
  }
2577
+ generateDecimalHelpers(eventArguments);
2505
2578
  for (const model of datamodel.models) {
2506
2579
  await eventEmitter.emit("Model", model, eventArguments);
2507
2580
  }