@prisma/query-plan-executor 7.1.0-dev.32 → 7.1.0-dev.34

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/index.d.ts CHANGED
@@ -34,8 +34,14 @@ declare class App {
34
34
  shutdown(): Promise<void>;
35
35
  /**
36
36
  * Executes a query plan and returns the result.
37
+ *
38
+ * @param queryPlan - The query plan to execute
39
+ * @param placeholderValues - Placeholder values for the query
40
+ * @param comments - Pre-computed SQL commenter tags from the client
41
+ * @param resourceLimits - Resource limits for the query
42
+ * @param transactionId - Transaction ID if running within a transaction
37
43
  */
38
- query(queryPlan: QueryPlanNode, placeholderValues: Record<string, unknown>, resourceLimits: ResourceLimits, transactionId: string | null): Promise<unknown>;
44
+ query(queryPlan: QueryPlanNode, placeholderValues: Record<string, unknown>, comments: Record<string, string> | undefined, resourceLimits: ResourceLimits, transactionId: string | null): Promise<unknown>;
39
45
  /**
40
46
  * Starts a new transaction.
41
47
  */
@@ -648,6 +654,7 @@ operation: string;
648
654
  plan: Record<string, unknown>;
649
655
  params: Record<string, unknown>;
650
656
  model?: string | undefined;
657
+ comments?: Record<string, string> | undefined;
651
658
  };
652
659
  };
653
660
  output: {
@@ -683,6 +690,7 @@ operation: string;
683
690
  plan: Record<string, unknown>;
684
691
  params: Record<string, unknown>;
685
692
  model?: string | undefined;
693
+ comments?: Record<string, string> | undefined;
686
694
  };
687
695
  } & {
688
696
  param: {
package/dist/index.js CHANGED
@@ -97752,7 +97752,7 @@ __export(index_exports, {
97752
97752
  module.exports = __toCommonJS(index_exports);
97753
97753
 
97754
97754
  // package.json
97755
- var version = "7.1.0-dev.32";
97755
+ var version = "7.1.0-dev.34";
97756
97756
 
97757
97757
  // ../../node_modules/.pnpm/temporal-polyfill@0.3.0/node_modules/temporal-polyfill/chunks/internal.js
97758
97758
  function clampProp(e2, n2, t2, o2, r2) {
@@ -106556,6 +106556,41 @@ function normalizeDateTime(dt2) {
106556
106556
  }
106557
106557
  return dtWithTz;
106558
106558
  }
106559
+ function formatSqlComment(tags) {
106560
+ const entries = Object.entries(tags);
106561
+ if (entries.length === 0) {
106562
+ return "";
106563
+ }
106564
+ entries.sort(([a2], [b2]) => a2.localeCompare(b2));
106565
+ const parts = entries.map(([key, value]) => {
106566
+ const encodedKey = encodeURIComponent(key);
106567
+ const encodedValue = encodeURIComponent(value).replace(/'/g, "\\'");
106568
+ return `${encodedKey}='${encodedValue}'`;
106569
+ });
106570
+ return `/*${parts.join(",")}*/`;
106571
+ }
106572
+ function applySqlCommenters(plugins, context2) {
106573
+ const merged = {};
106574
+ for (const plugin of plugins) {
106575
+ const tags = plugin(context2);
106576
+ for (const [key, value] of Object.entries(tags)) {
106577
+ if (value !== void 0) {
106578
+ merged[key] = value;
106579
+ }
106580
+ }
106581
+ }
106582
+ return merged;
106583
+ }
106584
+ function buildSqlComment(plugins, context2) {
106585
+ const tags = applySqlCommenters(plugins, context2);
106586
+ return formatSqlComment(tags);
106587
+ }
106588
+ function appendSqlComment(sql4, comment) {
106589
+ if (!comment) {
106590
+ return sql4;
106591
+ }
106592
+ return `${sql4} ${comment}`;
106593
+ }
106559
106594
  function providerToOtelSystem(provider) {
106560
106595
  switch (provider) {
106561
106596
  case "postgresql":
@@ -107280,6 +107315,7 @@ var QueryInterpreter = class _QueryInterpreter {
107280
107315
  #rawSerializer;
107281
107316
  #provider;
107282
107317
  #connectionInfo;
107318
+ #sqlCommenter;
107283
107319
  constructor({
107284
107320
  transactionManager,
107285
107321
  placeholderValues,
@@ -107288,7 +107324,8 @@ var QueryInterpreter = class _QueryInterpreter {
107288
107324
  serializer,
107289
107325
  rawSerializer,
107290
107326
  provider,
107291
- connectionInfo
107327
+ connectionInfo,
107328
+ sqlCommenter
107292
107329
  }) {
107293
107330
  this.#transactionManager = transactionManager;
107294
107331
  this.#placeholderValues = placeholderValues;
@@ -107298,6 +107335,7 @@ var QueryInterpreter = class _QueryInterpreter {
107298
107335
  this.#rawSerializer = rawSerializer ?? serializer;
107299
107336
  this.#provider = provider;
107300
107337
  this.#connectionInfo = connectionInfo;
107338
+ this.#sqlCommenter = sqlCommenter;
107301
107339
  }
107302
107340
  static forSql(options) {
107303
107341
  return new _QueryInterpreter({
@@ -107308,7 +107346,8 @@ var QueryInterpreter = class _QueryInterpreter {
107308
107346
  serializer: serializeSql,
107309
107347
  rawSerializer: serializeRawSql,
107310
107348
  provider: options.provider,
107311
- connectionInfo: options.connectionInfo
107349
+ connectionInfo: options.connectionInfo,
107350
+ sqlCommenter: options.sqlCommenter
107312
107351
  });
107313
107352
  }
107314
107353
  async run(queryPlan, queryable) {
@@ -107372,10 +107411,11 @@ var QueryInterpreter = class _QueryInterpreter {
107372
107411
  const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
107373
107412
  let sum2 = 0;
107374
107413
  for (const query2 of queries) {
107414
+ const commentedQuery = this.#applyComments(query2);
107375
107415
  sum2 += await this.#withQuerySpanAndEvent(
107376
- query2,
107416
+ commentedQuery,
107377
107417
  queryable,
107378
- () => queryable.executeRaw(query2).catch(
107418
+ () => queryable.executeRaw(commentedQuery).catch(
107379
107419
  (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
107380
107420
  )
107381
107421
  );
@@ -107386,10 +107426,11 @@ var QueryInterpreter = class _QueryInterpreter {
107386
107426
  const queries = renderQuery(node.args, scope, generators, this.#maxChunkSize());
107387
107427
  let results;
107388
107428
  for (const query2 of queries) {
107429
+ const commentedQuery = this.#applyComments(query2);
107389
107430
  const result = await this.#withQuerySpanAndEvent(
107390
- query2,
107431
+ commentedQuery,
107391
107432
  queryable,
107392
- () => queryable.queryRaw(query2).catch(
107433
+ () => queryable.queryRaw(commentedQuery).catch(
107393
107434
  (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
107394
107435
  )
107395
107436
  );
@@ -107547,6 +107588,22 @@ var QueryInterpreter = class _QueryInterpreter {
107547
107588
  onQuery: this.#onQuery
107548
107589
  });
107549
107590
  }
107591
+ #applyComments(query2) {
107592
+ if (!this.#sqlCommenter || this.#sqlCommenter.plugins.length === 0) {
107593
+ return query2;
107594
+ }
107595
+ const comment = buildSqlComment(this.#sqlCommenter.plugins, {
107596
+ query: this.#sqlCommenter.queryInfo,
107597
+ sql: query2.sql
107598
+ });
107599
+ if (!comment) {
107600
+ return query2;
107601
+ }
107602
+ return {
107603
+ ...query2,
107604
+ sql: appendSqlComment(query2.sql, comment)
107605
+ };
107606
+ }
107550
107607
  };
107551
107608
  function isEmpty(value) {
107552
107609
  if (Array.isArray(value)) {
@@ -111797,15 +111854,28 @@ var App = class _App {
111797
111854
  }
111798
111855
  /**
111799
111856
  * Executes a query plan and returns the result.
111857
+ *
111858
+ * @param queryPlan - The query plan to execute
111859
+ * @param placeholderValues - Placeholder values for the query
111860
+ * @param comments - Pre-computed SQL commenter tags from the client
111861
+ * @param resourceLimits - Resource limits for the query
111862
+ * @param transactionId - Transaction ID if running within a transaction
111800
111863
  */
111801
- async query(queryPlan, placeholderValues, resourceLimits, transactionId) {
111864
+ async query(queryPlan, placeholderValues, comments, resourceLimits, transactionId) {
111802
111865
  return await this.#tracingHandler.runInChildSpan("query", async () => {
111803
111866
  const queryable = transactionId !== null ? await this.#transactionManager.getTransaction({ id: transactionId }, "query") : this.#db;
111867
+ const sqlCommenter = comments && Object.keys(comments).length > 0 ? {
111868
+ plugins: [() => comments],
111869
+ // For pre-computed comments, we use a placeholder queryInfo since the actual
111870
+ // query info was already used on the client side to compute the comments
111871
+ queryInfo: { type: "single", action: "queryRaw", query: {} }
111872
+ } : void 0;
111804
111873
  const queryInterpreter = QueryInterpreter.forSql({
111805
111874
  placeholderValues,
111806
111875
  tracingHelper: this.#tracingHandler,
111807
111876
  transactionManager: transactionId === null ? { enabled: true, manager: this.#transactionManager } : { enabled: false },
111808
- onQuery: logQuery
111877
+ onQuery: logQuery,
111878
+ sqlCommenter
111809
111879
  });
111810
111880
  const result = await Promise.race([
111811
111881
  queryInterpreter.run(queryPlan, queryable),
@@ -124038,7 +124108,8 @@ var QueryRequestBody = external_exports.object({
124038
124108
  model: external_exports.string().min(1).optional(),
124039
124109
  operation: external_exports.string().min(1),
124040
124110
  plan: external_exports.record(external_exports.string(), external_exports.unknown()),
124041
- params: external_exports.record(external_exports.string(), external_exports.unknown())
124111
+ params: external_exports.record(external_exports.string(), external_exports.unknown()),
124112
+ comments: external_exports.record(external_exports.string(), external_exports.string()).optional()
124042
124113
  });
124043
124114
  var TransactionStartRequestBody = external_exports.object({
124044
124115
  timeout: external_exports.number().optional(),
@@ -124082,7 +124153,13 @@ function createHonoServer(app, options) {
124082
124153
  return c2.json(app.getConnectionInfo());
124083
124154
  }).post("/query", zValidator("json", QueryRequestBody), async (c2) => {
124084
124155
  const request3 = c2.req.valid("json");
124085
- const data = await app.query(request3.plan, request3.params, c2.get("resourceLimits"), null);
124156
+ const data = await app.query(
124157
+ request3.plan,
124158
+ request3.params,
124159
+ request3.comments,
124160
+ c2.get("resourceLimits"),
124161
+ null
124162
+ );
124086
124163
  return c2.json({ data });
124087
124164
  }).post("/transaction/start", zValidator("json", TransactionStartRequestBody), async (c2) => {
124088
124165
  const result = await app.startTransaction(c2.req.valid("json"), c2.get("resourceLimits"));
@@ -124093,6 +124170,7 @@ function createHonoServer(app, options) {
124093
124170
  const data = await app.query(
124094
124171
  request3.plan,
124095
124172
  request3.params,
124173
+ request3.comments,
124096
124174
  c2.get("resourceLimits"),
124097
124175
  c2.req.param("txId")
124098
124176
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/query-plan-executor",
3
- "version": "7.1.0-dev.32",
3
+ "version": "7.1.0-dev.34",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,11 +20,11 @@
20
20
  "temporal-polyfill": "0.3.0",
21
21
  "vitest": "3.2.4",
22
22
  "zod": "4.1.3",
23
- "@prisma/adapter-pg": "7.1.0-dev.32",
24
- "@prisma/adapter-mariadb": "7.1.0-dev.32",
25
- "@prisma/adapter-mssql": "7.1.0-dev.32",
26
- "@prisma/client-engine-runtime": "7.1.0-dev.32",
27
- "@prisma/driver-adapter-utils": "7.1.0-dev.32"
23
+ "@prisma/adapter-pg": "7.1.0-dev.34",
24
+ "@prisma/adapter-mssql": "7.1.0-dev.34",
25
+ "@prisma/adapter-mariadb": "7.1.0-dev.34",
26
+ "@prisma/client-engine-runtime": "7.1.0-dev.34",
27
+ "@prisma/driver-adapter-utils": "7.1.0-dev.34"
28
28
  },
29
29
  "files": [
30
30
  "dist"