prisma-sql 1.77.0 → 1.79.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 +63 -6
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +63 -6
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +27 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -68,7 +68,7 @@ var require_package = __commonJS({
|
|
|
68
68
|
"package.json"(exports$1, module) {
|
|
69
69
|
module.exports = {
|
|
70
70
|
name: "prisma-sql",
|
|
71
|
-
version: "1.
|
|
71
|
+
version: "1.79.0",
|
|
72
72
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
73
73
|
main: "dist/index.cjs",
|
|
74
74
|
module: "dist/index.js",
|
|
@@ -6285,6 +6285,31 @@ function normalizeArgsForDialect(dialect, args) {
|
|
|
6285
6285
|
if (dialect !== "postgres") return args;
|
|
6286
6286
|
return applyPostgresDistinctOrderBy(args);
|
|
6287
6287
|
}
|
|
6288
|
+
function normalizeCompoundCursor(cursor, model) {
|
|
6289
|
+
const keys = Object.keys(cursor);
|
|
6290
|
+
if (keys.length !== 1) return cursor;
|
|
6291
|
+
const key = keys[0];
|
|
6292
|
+
const value = cursor[key];
|
|
6293
|
+
const scalarSet = getScalarFieldSet(model);
|
|
6294
|
+
if (scalarSet.has(key)) return cursor;
|
|
6295
|
+
if (!isPlainObject(value)) return cursor;
|
|
6296
|
+
const nested = value;
|
|
6297
|
+
const nestedKeys = Object.keys(nested);
|
|
6298
|
+
if (nestedKeys.length === 0) return cursor;
|
|
6299
|
+
for (const nk of nestedKeys) {
|
|
6300
|
+
if (!scalarSet.has(nk)) return cursor;
|
|
6301
|
+
}
|
|
6302
|
+
return nested;
|
|
6303
|
+
}
|
|
6304
|
+
function normalizeArgsCompoundCursor(args, model) {
|
|
6305
|
+
if (!isNotNullish(args.cursor) || !isPlainObject(args.cursor)) return args;
|
|
6306
|
+
const flat = normalizeCompoundCursor(
|
|
6307
|
+
args.cursor,
|
|
6308
|
+
model
|
|
6309
|
+
);
|
|
6310
|
+
if (flat === args.cursor) return args;
|
|
6311
|
+
return __spreadProps(__spreadValues({}, args), { cursor: flat });
|
|
6312
|
+
}
|
|
6288
6313
|
function buildCursorClauseIfAny(input) {
|
|
6289
6314
|
const { cursor, orderBy, tableName, alias, params, skip, dialect, model } = input;
|
|
6290
6315
|
if (!isNotNullish(cursor)) return {};
|
|
@@ -6382,7 +6407,8 @@ function buildSelectSql(input) {
|
|
|
6382
6407
|
assertSafeTableRef(from.tableName);
|
|
6383
6408
|
const dialectToUse = resolveDialect(dialect);
|
|
6384
6409
|
const argsForSql = normalizeArgsForNegativeTake(method, args);
|
|
6385
|
-
const
|
|
6410
|
+
const argsWithDialect = normalizeArgsForDialect(dialectToUse, argsForSql);
|
|
6411
|
+
const normalizedArgs = normalizeArgsCompoundCursor(argsWithDialect, model);
|
|
6386
6412
|
validateDistinct(model, normalizedArgs.distinct);
|
|
6387
6413
|
validateOrderBy(model, normalizedArgs.orderBy);
|
|
6388
6414
|
validateCursor(model, normalizedArgs.cursor, normalizedArgs.distinct);
|
|
@@ -7833,6 +7859,23 @@ function resolveParamsFromMappings(args: any, paramMappings: any[]): unknown[] {
|
|
|
7833
7859
|
params.push(normalizeValue(value))
|
|
7834
7860
|
}
|
|
7835
7861
|
return params
|
|
7862
|
+
}
|
|
7863
|
+
|
|
7864
|
+
function normalizeCompoundCursor(cursor: any, model: any): any {
|
|
7865
|
+
if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || cursor instanceof Date) return cursor
|
|
7866
|
+
const keys = Object.keys(cursor)
|
|
7867
|
+
if (keys.length !== 1) return cursor
|
|
7868
|
+
const key = keys[0]
|
|
7869
|
+
const value = cursor[key]
|
|
7870
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) return cursor
|
|
7871
|
+
const scalarSet = new Set(model.fields.filter((f: any) => !f.isRelation).map((f: any) => f.name))
|
|
7872
|
+
if (scalarSet.has(key)) return cursor
|
|
7873
|
+
const nestedKeys = Object.keys(value)
|
|
7874
|
+
if (nestedKeys.length === 0) return cursor
|
|
7875
|
+
for (const nk of nestedKeys) {
|
|
7876
|
+
if (!scalarSet.has(nk)) return cursor
|
|
7877
|
+
}
|
|
7878
|
+
return value
|
|
7836
7879
|
}`;
|
|
7837
7880
|
}
|
|
7838
7881
|
function generateDataConstants(cleanModels, mappings, fieldTypes, queries, dialect) {
|
|
@@ -8137,7 +8180,7 @@ function generateExtension(runtimeImportPath) {
|
|
|
8137
8180
|
$parent?: any
|
|
8138
8181
|
}
|
|
8139
8182
|
|
|
8140
|
-
|
|
8183
|
+
async function handleMethod(
|
|
8141
8184
|
this: ModelContext,
|
|
8142
8185
|
method: PrismaMethod,
|
|
8143
8186
|
args: unknown
|
|
@@ -8149,6 +8192,7 @@ function generateExtension(runtimeImportPath) {
|
|
|
8149
8192
|
}
|
|
8150
8193
|
|
|
8151
8194
|
const startTime = Date.now()
|
|
8195
|
+
let sql: string | undefined
|
|
8152
8196
|
|
|
8153
8197
|
try {
|
|
8154
8198
|
if (args !== undefined && args !== null && typeof args !== 'object') {
|
|
@@ -8157,7 +8201,7 @@ function generateExtension(runtimeImportPath) {
|
|
|
8157
8201
|
)
|
|
8158
8202
|
}
|
|
8159
8203
|
|
|
8160
|
-
|
|
8204
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8161
8205
|
|
|
8162
8206
|
const model = MODEL_MAP.get(modelName)
|
|
8163
8207
|
if (!model) {
|
|
@@ -8167,6 +8211,13 @@ function generateExtension(runtimeImportPath) {
|
|
|
8167
8211
|
return this.$parent[modelName][method](args)
|
|
8168
8212
|
}
|
|
8169
8213
|
|
|
8214
|
+
if (transformedArgs.cursor) {
|
|
8215
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8216
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8217
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8218
|
+
}
|
|
8219
|
+
}
|
|
8220
|
+
|
|
8170
8221
|
const plan = planQueryStrategy({
|
|
8171
8222
|
model,
|
|
8172
8223
|
method,
|
|
@@ -8177,7 +8228,6 @@ function generateExtension(runtimeImportPath) {
|
|
|
8177
8228
|
|
|
8178
8229
|
const queryKey = normalizeQuery(plan.filteredArgs)
|
|
8179
8230
|
const prebakedQuery = QUERIES[modelName]?.[method]?.[queryKey]
|
|
8180
|
-
let sql: string
|
|
8181
8231
|
let params: unknown[]
|
|
8182
8232
|
let prebaked = false
|
|
8183
8233
|
let requiresReduction = false
|
|
@@ -8330,12 +8380,19 @@ function generateExtension(runtimeImportPath) {
|
|
|
8330
8380
|
throw new Error('Streaming requires postgres.js client')
|
|
8331
8381
|
}
|
|
8332
8382
|
|
|
8333
|
-
|
|
8383
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8334
8384
|
const model = MODEL_MAP.get(modelName)
|
|
8335
8385
|
if (!model) {
|
|
8336
8386
|
throw new Error(\`Model '\${modelName}' not found\`)
|
|
8337
8387
|
}
|
|
8338
8388
|
|
|
8389
|
+
if (transformedArgs.cursor) {
|
|
8390
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8391
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8392
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8393
|
+
}
|
|
8394
|
+
}
|
|
8395
|
+
|
|
8339
8396
|
const plan = planQueryStrategy({
|
|
8340
8397
|
model,
|
|
8341
8398
|
method: 'findMany',
|