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.cjs
CHANGED
|
@@ -56,7 +56,7 @@ var require_package = __commonJS({
|
|
|
56
56
|
"package.json"(exports$1, module) {
|
|
57
57
|
module.exports = {
|
|
58
58
|
name: "prisma-sql",
|
|
59
|
-
version: "1.
|
|
59
|
+
version: "1.43.0",
|
|
60
60
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
61
61
|
main: "dist/index.cjs",
|
|
62
62
|
module: "dist/index.js",
|
|
@@ -4677,6 +4677,18 @@ function generateCode(models, queries, dialect, datamodel) {
|
|
|
4677
4677
|
return `// Generated by @prisma-sql/generator - DO NOT EDIT
|
|
4678
4678
|
import { buildSQL, transformQueryResults, type PrismaMethod, type Model } from 'prisma-sql'
|
|
4679
4679
|
|
|
4680
|
+
function normalizeValue(value: unknown): unknown {
|
|
4681
|
+
if (value instanceof Date) {
|
|
4682
|
+
return value.toISOString()
|
|
4683
|
+
}
|
|
4684
|
+
|
|
4685
|
+
if (Array.isArray(value)) {
|
|
4686
|
+
return value.map(normalizeValue)
|
|
4687
|
+
}
|
|
4688
|
+
|
|
4689
|
+
return value
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4680
4692
|
export const MODELS: Model[] = ${JSON.stringify(cleanModels, null, 2)}
|
|
4681
4693
|
|
|
4682
4694
|
const ENUM_MAPPINGS: Record<string, Record<string, string>> = ${JSON.stringify(mappings, null, 2)}
|
|
@@ -4706,7 +4718,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4706
4718
|
return value
|
|
4707
4719
|
}
|
|
4708
4720
|
|
|
4709
|
-
// Handle array of enum values
|
|
4710
4721
|
if (Array.isArray(value)) {
|
|
4711
4722
|
return value.map(v => {
|
|
4712
4723
|
if (typeof v === 'string' && mapping[v] !== undefined) {
|
|
@@ -4716,7 +4727,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4716
4727
|
})
|
|
4717
4728
|
}
|
|
4718
4729
|
|
|
4719
|
-
// Handle single enum value
|
|
4720
4730
|
if (typeof value === 'string' && mapping[value] !== undefined) {
|
|
4721
4731
|
return mapping[value]
|
|
4722
4732
|
}
|
|
@@ -4740,24 +4750,19 @@ function transformEnumValues(modelName: string, obj: any, currentPath: string[]
|
|
|
4740
4750
|
for (const [key, value] of Object.entries(obj)) {
|
|
4741
4751
|
const newPath = [...currentPath, key]
|
|
4742
4752
|
|
|
4743
|
-
// Check if current key is an enum field at root level
|
|
4744
4753
|
const enumType = modelFields[key]
|
|
4745
4754
|
|
|
4746
4755
|
if (enumType) {
|
|
4747
|
-
// This is an enum field - check if value is direct or has operators
|
|
4748
4756
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
4749
|
-
// Has operators like { equals: "ACTIVE" }, { in: ["ACTIVE"] }, etc.
|
|
4750
4757
|
const transformedOperators: any = {}
|
|
4751
4758
|
for (const [op, opValue] of Object.entries(value)) {
|
|
4752
4759
|
transformedOperators[op] = transformEnumInValue(opValue, enumType)
|
|
4753
4760
|
}
|
|
4754
4761
|
transformed[key] = transformedOperators
|
|
4755
4762
|
} else {
|
|
4756
|
-
// Direct value like { status: "ACTIVE" }
|
|
4757
4763
|
transformed[key] = transformEnumInValue(value, enumType)
|
|
4758
4764
|
}
|
|
4759
4765
|
} else if (typeof value === 'object' && value !== null) {
|
|
4760
|
-
// Recursively transform nested objects (relations, logical operators, etc)
|
|
4761
4766
|
transformed[key] = transformEnumValues(modelName, value, newPath)
|
|
4762
4767
|
} else {
|
|
4763
4768
|
transformed[key] = value
|
|
@@ -4833,7 +4838,7 @@ function extractDynamicParams(args: any, dynamicKeys: string[]): unknown[] {
|
|
|
4833
4838
|
throw new Error(\`Missing required parameter: \${key}\`)
|
|
4834
4839
|
}
|
|
4835
4840
|
|
|
4836
|
-
params.push(value)
|
|
4841
|
+
params.push(normalizeValue(value))
|
|
4837
4842
|
}
|
|
4838
4843
|
|
|
4839
4844
|
return params
|
|
@@ -4884,7 +4889,6 @@ export function speedExtension(config: {
|
|
|
4884
4889
|
const modelName = this?.name || this?.$name
|
|
4885
4890
|
const startTime = Date.now()
|
|
4886
4891
|
|
|
4887
|
-
// Transform enum values before processing
|
|
4888
4892
|
const transformedArgs = transformEnumValues(modelName, args || {})
|
|
4889
4893
|
|
|
4890
4894
|
const queryKey = normalizeQuery(transformedArgs)
|