prisma-sql 1.42.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.cjs +14 -10
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +14 -10
- package/dist/generator.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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",
|
|
@@ -4675,6 +4675,18 @@ function generateCode(models, queries, dialect, datamodel) {
|
|
|
4675
4675
|
return `// Generated by @prisma-sql/generator - DO NOT EDIT
|
|
4676
4676
|
import { buildSQL, transformQueryResults, type PrismaMethod, type Model } from 'prisma-sql'
|
|
4677
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
|
+
|
|
4678
4690
|
export const MODELS: Model[] = ${JSON.stringify(cleanModels, null, 2)}
|
|
4679
4691
|
|
|
4680
4692
|
const ENUM_MAPPINGS: Record<string, Record<string, string>> = ${JSON.stringify(mappings, null, 2)}
|
|
@@ -4704,7 +4716,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4704
4716
|
return value
|
|
4705
4717
|
}
|
|
4706
4718
|
|
|
4707
|
-
// Handle array of enum values
|
|
4708
4719
|
if (Array.isArray(value)) {
|
|
4709
4720
|
return value.map(v => {
|
|
4710
4721
|
if (typeof v === 'string' && mapping[v] !== undefined) {
|
|
@@ -4714,7 +4725,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4714
4725
|
})
|
|
4715
4726
|
}
|
|
4716
4727
|
|
|
4717
|
-
// Handle single enum value
|
|
4718
4728
|
if (typeof value === 'string' && mapping[value] !== undefined) {
|
|
4719
4729
|
return mapping[value]
|
|
4720
4730
|
}
|
|
@@ -4738,24 +4748,19 @@ function transformEnumValues(modelName: string, obj: any, currentPath: string[]
|
|
|
4738
4748
|
for (const [key, value] of Object.entries(obj)) {
|
|
4739
4749
|
const newPath = [...currentPath, key]
|
|
4740
4750
|
|
|
4741
|
-
// Check if current key is an enum field at root level
|
|
4742
4751
|
const enumType = modelFields[key]
|
|
4743
4752
|
|
|
4744
4753
|
if (enumType) {
|
|
4745
|
-
// This is an enum field - check if value is direct or has operators
|
|
4746
4754
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
4747
|
-
// Has operators like { equals: "ACTIVE" }, { in: ["ACTIVE"] }, etc.
|
|
4748
4755
|
const transformedOperators: any = {}
|
|
4749
4756
|
for (const [op, opValue] of Object.entries(value)) {
|
|
4750
4757
|
transformedOperators[op] = transformEnumInValue(opValue, enumType)
|
|
4751
4758
|
}
|
|
4752
4759
|
transformed[key] = transformedOperators
|
|
4753
4760
|
} else {
|
|
4754
|
-
// Direct value like { status: "ACTIVE" }
|
|
4755
4761
|
transformed[key] = transformEnumInValue(value, enumType)
|
|
4756
4762
|
}
|
|
4757
4763
|
} else if (typeof value === 'object' && value !== null) {
|
|
4758
|
-
// Recursively transform nested objects (relations, logical operators, etc)
|
|
4759
4764
|
transformed[key] = transformEnumValues(modelName, value, newPath)
|
|
4760
4765
|
} else {
|
|
4761
4766
|
transformed[key] = value
|
|
@@ -4831,7 +4836,7 @@ function extractDynamicParams(args: any, dynamicKeys: string[]): unknown[] {
|
|
|
4831
4836
|
throw new Error(\`Missing required parameter: \${key}\`)
|
|
4832
4837
|
}
|
|
4833
4838
|
|
|
4834
|
-
params.push(value)
|
|
4839
|
+
params.push(normalizeValue(value))
|
|
4835
4840
|
}
|
|
4836
4841
|
|
|
4837
4842
|
return params
|
|
@@ -4882,7 +4887,6 @@ export function speedExtension(config: {
|
|
|
4882
4887
|
const modelName = this?.name || this?.$name
|
|
4883
4888
|
const startTime = Date.now()
|
|
4884
4889
|
|
|
4885
|
-
// Transform enum values before processing
|
|
4886
4890
|
const transformedArgs = transformEnumValues(modelName, args || {})
|
|
4887
4891
|
|
|
4888
4892
|
const queryKey = normalizeQuery(transformedArgs)
|