prisma-sql 1.41.0 → 1.43.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/generator.js CHANGED
@@ -54,7 +54,7 @@ var require_package = __commonJS({
54
54
  "package.json"(exports$1, module) {
55
55
  module.exports = {
56
56
  name: "prisma-sql",
57
- version: "1.41.0",
57
+ version: "1.43.0",
58
58
  description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
59
59
  main: "dist/index.cjs",
60
60
  module: "dist/index.js",
@@ -3810,7 +3810,12 @@ function buildSelectSpec(input) {
3810
3810
  model,
3811
3811
  alias
3812
3812
  );
3813
- const orderByClause = buildOrderByClause(normalizedArgs, alias, dialect);
3813
+ const orderByClause = buildOrderByClause(
3814
+ normalizedArgs,
3815
+ alias,
3816
+ dialect,
3817
+ model
3818
+ );
3814
3819
  const { take, skip, cursor } = getPaginationParams(method, normalizedArgs);
3815
3820
  const params = createParamStoreFrom(
3816
3821
  whereResult.params,
@@ -4670,6 +4675,18 @@ function generateCode(models, queries, dialect, datamodel) {
4670
4675
  return `// Generated by @prisma-sql/generator - DO NOT EDIT
4671
4676
  import { buildSQL, transformQueryResults, type PrismaMethod, type Model } from 'prisma-sql'
4672
4677
 
4678
+ function normalizeValue(value: unknown): unknown {
4679
+ if (value instanceof Date) {
4680
+ return value.toISOString()
4681
+ }
4682
+
4683
+ if (Array.isArray(value)) {
4684
+ return value.map(normalizeValue)
4685
+ }
4686
+
4687
+ return value
4688
+ }
4689
+
4673
4690
  export const MODELS: Model[] = ${JSON.stringify(cleanModels, null, 2)}
4674
4691
 
4675
4692
  const ENUM_MAPPINGS: Record<string, Record<string, string>> = ${JSON.stringify(mappings, null, 2)}
@@ -4699,7 +4716,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
4699
4716
  return value
4700
4717
  }
4701
4718
 
4702
- // Handle array of enum values
4703
4719
  if (Array.isArray(value)) {
4704
4720
  return value.map(v => {
4705
4721
  if (typeof v === 'string' && mapping[v] !== undefined) {
@@ -4709,7 +4725,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
4709
4725
  })
4710
4726
  }
4711
4727
 
4712
- // Handle single enum value
4713
4728
  if (typeof value === 'string' && mapping[value] !== undefined) {
4714
4729
  return mapping[value]
4715
4730
  }
@@ -4733,24 +4748,19 @@ function transformEnumValues(modelName: string, obj: any, currentPath: string[]
4733
4748
  for (const [key, value] of Object.entries(obj)) {
4734
4749
  const newPath = [...currentPath, key]
4735
4750
 
4736
- // Check if current key is an enum field at root level
4737
4751
  const enumType = modelFields[key]
4738
4752
 
4739
4753
  if (enumType) {
4740
- // This is an enum field - check if value is direct or has operators
4741
4754
  if (value && typeof value === 'object' && !Array.isArray(value)) {
4742
- // Has operators like { equals: "ACTIVE" }, { in: ["ACTIVE"] }, etc.
4743
4755
  const transformedOperators: any = {}
4744
4756
  for (const [op, opValue] of Object.entries(value)) {
4745
4757
  transformedOperators[op] = transformEnumInValue(opValue, enumType)
4746
4758
  }
4747
4759
  transformed[key] = transformedOperators
4748
4760
  } else {
4749
- // Direct value like { status: "ACTIVE" }
4750
4761
  transformed[key] = transformEnumInValue(value, enumType)
4751
4762
  }
4752
4763
  } else if (typeof value === 'object' && value !== null) {
4753
- // Recursively transform nested objects (relations, logical operators, etc)
4754
4764
  transformed[key] = transformEnumValues(modelName, value, newPath)
4755
4765
  } else {
4756
4766
  transformed[key] = value
@@ -4826,7 +4836,7 @@ function extractDynamicParams(args: any, dynamicKeys: string[]): unknown[] {
4826
4836
  throw new Error(\`Missing required parameter: \${key}\`)
4827
4837
  }
4828
4838
 
4829
- params.push(value)
4839
+ params.push(normalizeValue(value))
4830
4840
  }
4831
4841
 
4832
4842
  return params
@@ -4877,7 +4887,6 @@ export function speedExtension(config: {
4877
4887
  const modelName = this?.name || this?.$name
4878
4888
  const startTime = Date.now()
4879
4889
 
4880
- // Transform enum values before processing
4881
4890
  const transformedArgs = transformEnumValues(modelName, args || {})
4882
4891
 
4883
4892
  const queryKey = normalizeQuery(transformedArgs)