prisma-sql 1.77.0 → 1.78.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 +61 -4
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +61 -4
- 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.cjs
CHANGED
|
@@ -70,7 +70,7 @@ var require_package = __commonJS({
|
|
|
70
70
|
"package.json"(exports$1, module) {
|
|
71
71
|
module.exports = {
|
|
72
72
|
name: "prisma-sql",
|
|
73
|
-
version: "1.
|
|
73
|
+
version: "1.78.0",
|
|
74
74
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
75
75
|
main: "dist/index.cjs",
|
|
76
76
|
module: "dist/index.js",
|
|
@@ -6287,6 +6287,31 @@ function normalizeArgsForDialect(dialect, args) {
|
|
|
6287
6287
|
if (dialect !== "postgres") return args;
|
|
6288
6288
|
return applyPostgresDistinctOrderBy(args);
|
|
6289
6289
|
}
|
|
6290
|
+
function normalizeCompoundCursor(cursor, model) {
|
|
6291
|
+
const keys = Object.keys(cursor);
|
|
6292
|
+
if (keys.length !== 1) return cursor;
|
|
6293
|
+
const key = keys[0];
|
|
6294
|
+
const value = cursor[key];
|
|
6295
|
+
const scalarSet = getScalarFieldSet(model);
|
|
6296
|
+
if (scalarSet.has(key)) return cursor;
|
|
6297
|
+
if (!isPlainObject(value)) return cursor;
|
|
6298
|
+
const nested = value;
|
|
6299
|
+
const nestedKeys = Object.keys(nested);
|
|
6300
|
+
if (nestedKeys.length === 0) return cursor;
|
|
6301
|
+
for (const nk of nestedKeys) {
|
|
6302
|
+
if (!scalarSet.has(nk)) return cursor;
|
|
6303
|
+
}
|
|
6304
|
+
return nested;
|
|
6305
|
+
}
|
|
6306
|
+
function normalizeArgsCompoundCursor(args, model) {
|
|
6307
|
+
if (!isNotNullish(args.cursor) || !isPlainObject(args.cursor)) return args;
|
|
6308
|
+
const flat = normalizeCompoundCursor(
|
|
6309
|
+
args.cursor,
|
|
6310
|
+
model
|
|
6311
|
+
);
|
|
6312
|
+
if (flat === args.cursor) return args;
|
|
6313
|
+
return __spreadProps(__spreadValues({}, args), { cursor: flat });
|
|
6314
|
+
}
|
|
6290
6315
|
function buildCursorClauseIfAny(input) {
|
|
6291
6316
|
const { cursor, orderBy, tableName, alias, params, skip, dialect, model } = input;
|
|
6292
6317
|
if (!isNotNullish(cursor)) return {};
|
|
@@ -6384,7 +6409,8 @@ function buildSelectSql(input) {
|
|
|
6384
6409
|
assertSafeTableRef(from.tableName);
|
|
6385
6410
|
const dialectToUse = resolveDialect(dialect);
|
|
6386
6411
|
const argsForSql = normalizeArgsForNegativeTake(method, args);
|
|
6387
|
-
const
|
|
6412
|
+
const argsWithDialect = normalizeArgsForDialect(dialectToUse, argsForSql);
|
|
6413
|
+
const normalizedArgs = normalizeArgsCompoundCursor(argsWithDialect, model);
|
|
6388
6414
|
validateDistinct(model, normalizedArgs.distinct);
|
|
6389
6415
|
validateOrderBy(model, normalizedArgs.orderBy);
|
|
6390
6416
|
validateCursor(model, normalizedArgs.cursor, normalizedArgs.distinct);
|
|
@@ -7835,6 +7861,23 @@ function resolveParamsFromMappings(args: any, paramMappings: any[]): unknown[] {
|
|
|
7835
7861
|
params.push(normalizeValue(value))
|
|
7836
7862
|
}
|
|
7837
7863
|
return params
|
|
7864
|
+
}
|
|
7865
|
+
|
|
7866
|
+
function normalizeCompoundCursor(cursor: any, model: any): any {
|
|
7867
|
+
if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || cursor instanceof Date) return cursor
|
|
7868
|
+
const keys = Object.keys(cursor)
|
|
7869
|
+
if (keys.length !== 1) return cursor
|
|
7870
|
+
const key = keys[0]
|
|
7871
|
+
const value = cursor[key]
|
|
7872
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) return cursor
|
|
7873
|
+
const scalarSet = new Set(model.fields.filter((f: any) => !f.isRelation).map((f: any) => f.name))
|
|
7874
|
+
if (scalarSet.has(key)) return cursor
|
|
7875
|
+
const nestedKeys = Object.keys(value)
|
|
7876
|
+
if (nestedKeys.length === 0) return cursor
|
|
7877
|
+
for (const nk of nestedKeys) {
|
|
7878
|
+
if (!scalarSet.has(nk)) return cursor
|
|
7879
|
+
}
|
|
7880
|
+
return value
|
|
7838
7881
|
}`;
|
|
7839
7882
|
}
|
|
7840
7883
|
function generateDataConstants(cleanModels, mappings, fieldTypes, queries, dialect) {
|
|
@@ -8159,7 +8202,7 @@ function generateExtension(runtimeImportPath) {
|
|
|
8159
8202
|
)
|
|
8160
8203
|
}
|
|
8161
8204
|
|
|
8162
|
-
|
|
8205
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8163
8206
|
|
|
8164
8207
|
const model = MODEL_MAP.get(modelName)
|
|
8165
8208
|
if (!model) {
|
|
@@ -8169,6 +8212,13 @@ function generateExtension(runtimeImportPath) {
|
|
|
8169
8212
|
return this.$parent[modelName][method](args)
|
|
8170
8213
|
}
|
|
8171
8214
|
|
|
8215
|
+
if (transformedArgs.cursor) {
|
|
8216
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8217
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8218
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8219
|
+
}
|
|
8220
|
+
}
|
|
8221
|
+
|
|
8172
8222
|
const plan = planQueryStrategy({
|
|
8173
8223
|
model,
|
|
8174
8224
|
method,
|
|
@@ -8332,12 +8382,19 @@ function generateExtension(runtimeImportPath) {
|
|
|
8332
8382
|
throw new Error('Streaming requires postgres.js client')
|
|
8333
8383
|
}
|
|
8334
8384
|
|
|
8335
|
-
|
|
8385
|
+
let transformedArgs = transformEnumValuesByModel(modelName, args || {})
|
|
8336
8386
|
const model = MODEL_MAP.get(modelName)
|
|
8337
8387
|
if (!model) {
|
|
8338
8388
|
throw new Error(\`Model '\${modelName}' not found\`)
|
|
8339
8389
|
}
|
|
8340
8390
|
|
|
8391
|
+
if (transformedArgs.cursor) {
|
|
8392
|
+
const flatCursor = normalizeCompoundCursor(transformedArgs.cursor, model)
|
|
8393
|
+
if (flatCursor !== transformedArgs.cursor) {
|
|
8394
|
+
transformedArgs = { ...transformedArgs, cursor: flatCursor }
|
|
8395
|
+
}
|
|
8396
|
+
}
|
|
8397
|
+
|
|
8341
8398
|
const plan = planQueryStrategy({
|
|
8342
8399
|
model,
|
|
8343
8400
|
method: 'findMany',
|