@prisma/client-engine-runtime 7.3.0-dev.7 → 7.3.0-dev.9

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.mts CHANGED
@@ -447,6 +447,7 @@ export declare type SchemaProvider = 'cockroachdb' | 'mongodb' | 'mysql' | 'post
447
447
  declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
448
448
 
449
449
  export declare interface TracingHelper {
450
+ isEnabled(): boolean;
450
451
  runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
451
452
  }
452
453
 
package/dist/index.d.ts CHANGED
@@ -447,6 +447,7 @@ export declare type SchemaProvider = 'cockroachdb' | 'mongodb' | 'mysql' | 'post
447
447
  declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
448
448
 
449
449
  export declare interface TracingHelper {
450
+ isEnabled(): boolean;
450
451
  runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
451
452
  }
452
453
 
package/dist/index.js CHANGED
@@ -455,6 +455,15 @@ var DataMapperError = class extends UserFacingError {
455
455
  super(message, "P2023", options);
456
456
  }
457
457
  };
458
+ var fieldEntriesCache = /* @__PURE__ */ new WeakMap();
459
+ function getFieldEntries(fields) {
460
+ let entries = fieldEntriesCache.get(fields);
461
+ if (!entries) {
462
+ entries = Object.entries(fields);
463
+ fieldEntriesCache.set(fields, entries);
464
+ }
465
+ return entries;
466
+ }
458
467
  function applyDataMap(data, structure, enums) {
459
468
  switch (structure.type) {
460
469
  case "affectedRows":
@@ -501,19 +510,20 @@ function mapObject(data, fields, enums) {
501
510
  throw new DataMapperError(`Expected an object, but got '${typeof data}'`);
502
511
  }
503
512
  const result = {};
504
- for (const [name, node] of Object.entries(fields)) {
513
+ for (const [name, node] of getFieldEntries(fields)) {
505
514
  switch (node.type) {
506
515
  case "affectedRows": {
507
516
  throw new DataMapperError(`Unexpected 'AffectedRows' node in data mapping for field '${name}'`);
508
517
  }
509
518
  case "object": {
510
- if (node.serializedName !== null && !Object.hasOwn(data, node.serializedName)) {
519
+ const { serializedName, fields: nodeFields, skipNulls } = node;
520
+ if (serializedName !== null && !Object.hasOwn(data, serializedName)) {
511
521
  throw new DataMapperError(
512
522
  `Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
513
523
  );
514
524
  }
515
- const target = node.serializedName !== null ? data[node.serializedName] : data;
516
- result[name] = mapArrayOrObject(target, node.fields, enums, node.skipNulls);
525
+ const target = serializedName !== null ? data[serializedName] : data;
526
+ result[name] = mapArrayOrObject(target, nodeFields, enums, skipNulls);
517
527
  break;
518
528
  }
519
529
  case "field":
@@ -740,6 +750,9 @@ function appendSqlComment(sql, comment) {
740
750
  // src/tracing.ts
741
751
  var import_api = require("@opentelemetry/api");
742
752
  var noopTracingHelper = {
753
+ isEnabled() {
754
+ return false;
755
+ },
743
756
  runInChildSpan(_, callback) {
744
757
  return callback();
745
758
  }
@@ -768,6 +781,22 @@ async function withQuerySpanAndEvent({
768
781
  onQuery,
769
782
  execute
770
783
  }) {
784
+ const callback = onQuery === void 0 ? execute : async () => {
785
+ const timestamp = /* @__PURE__ */ new Date();
786
+ const startInstant = performance.now();
787
+ const result = await execute();
788
+ const endInstant = performance.now();
789
+ onQuery({
790
+ timestamp,
791
+ duration: endInstant - startInstant,
792
+ query: query.sql,
793
+ params: query.args
794
+ });
795
+ return result;
796
+ };
797
+ if (!tracingHelper.isEnabled()) {
798
+ return callback();
799
+ }
771
800
  return await tracingHelper.runInChildSpan(
772
801
  {
773
802
  name: "db_query",
@@ -777,19 +806,7 @@ async function withQuerySpanAndEvent({
777
806
  "db.system.name": providerToOtelSystem(provider)
778
807
  }
779
808
  },
780
- async () => {
781
- const timestamp = /* @__PURE__ */ new Date();
782
- const startInstant = performance.now();
783
- const result = await execute();
784
- const endInstant = performance.now();
785
- onQuery?.({
786
- timestamp,
787
- duration: endInstant - startInstant,
788
- query: query.sql,
789
- params: query.args
790
- });
791
- return result;
792
- }
809
+ callback
793
810
  );
794
811
  }
795
812
 
package/dist/index.mjs CHANGED
@@ -404,6 +404,15 @@ var DataMapperError = class extends UserFacingError {
404
404
  super(message, "P2023", options);
405
405
  }
406
406
  };
407
+ var fieldEntriesCache = /* @__PURE__ */ new WeakMap();
408
+ function getFieldEntries(fields) {
409
+ let entries = fieldEntriesCache.get(fields);
410
+ if (!entries) {
411
+ entries = Object.entries(fields);
412
+ fieldEntriesCache.set(fields, entries);
413
+ }
414
+ return entries;
415
+ }
407
416
  function applyDataMap(data, structure, enums) {
408
417
  switch (structure.type) {
409
418
  case "affectedRows":
@@ -450,19 +459,20 @@ function mapObject(data, fields, enums) {
450
459
  throw new DataMapperError(`Expected an object, but got '${typeof data}'`);
451
460
  }
452
461
  const result = {};
453
- for (const [name, node] of Object.entries(fields)) {
462
+ for (const [name, node] of getFieldEntries(fields)) {
454
463
  switch (node.type) {
455
464
  case "affectedRows": {
456
465
  throw new DataMapperError(`Unexpected 'AffectedRows' node in data mapping for field '${name}'`);
457
466
  }
458
467
  case "object": {
459
- if (node.serializedName !== null && !Object.hasOwn(data, node.serializedName)) {
468
+ const { serializedName, fields: nodeFields, skipNulls } = node;
469
+ if (serializedName !== null && !Object.hasOwn(data, serializedName)) {
460
470
  throw new DataMapperError(
461
471
  `Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
462
472
  );
463
473
  }
464
- const target = node.serializedName !== null ? data[node.serializedName] : data;
465
- result[name] = mapArrayOrObject(target, node.fields, enums, node.skipNulls);
474
+ const target = serializedName !== null ? data[serializedName] : data;
475
+ result[name] = mapArrayOrObject(target, nodeFields, enums, skipNulls);
466
476
  break;
467
477
  }
468
478
  case "field":
@@ -689,6 +699,9 @@ function appendSqlComment(sql, comment) {
689
699
  // src/tracing.ts
690
700
  import { SpanKind } from "@opentelemetry/api";
691
701
  var noopTracingHelper = {
702
+ isEnabled() {
703
+ return false;
704
+ },
692
705
  runInChildSpan(_, callback) {
693
706
  return callback();
694
707
  }
@@ -717,6 +730,22 @@ async function withQuerySpanAndEvent({
717
730
  onQuery,
718
731
  execute
719
732
  }) {
733
+ const callback = onQuery === void 0 ? execute : async () => {
734
+ const timestamp = /* @__PURE__ */ new Date();
735
+ const startInstant = performance.now();
736
+ const result = await execute();
737
+ const endInstant = performance.now();
738
+ onQuery({
739
+ timestamp,
740
+ duration: endInstant - startInstant,
741
+ query: query.sql,
742
+ params: query.args
743
+ });
744
+ return result;
745
+ };
746
+ if (!tracingHelper.isEnabled()) {
747
+ return callback();
748
+ }
720
749
  return await tracingHelper.runInChildSpan(
721
750
  {
722
751
  name: "db_query",
@@ -726,19 +755,7 @@ async function withQuerySpanAndEvent({
726
755
  "db.system.name": providerToOtelSystem(provider)
727
756
  }
728
757
  },
729
- async () => {
730
- const timestamp = /* @__PURE__ */ new Date();
731
- const startInstant = performance.now();
732
- const result = await execute();
733
- const endInstant = performance.now();
734
- onQuery?.({
735
- timestamp,
736
- duration: endInstant - startInstant,
737
- query: query.sql,
738
- params: query.args
739
- });
740
- return result;
741
- }
758
+ callback
742
759
  );
743
760
  }
744
761
 
package/dist/tracing.d.ts CHANGED
@@ -7,6 +7,7 @@ export type ExtendedSpanOptions = SpanOptions & {
7
7
  name: string;
8
8
  };
9
9
  export interface TracingHelper {
10
+ isEnabled(): boolean;
10
11
  runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
11
12
  }
12
13
  export declare const noopTracingHelper: TracingHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "7.3.0-dev.7",
3
+ "version": "7.3.0-dev.9",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,10 +31,10 @@
31
31
  "nanoid": "5.1.5",
32
32
  "ulid": "3.0.0",
33
33
  "uuid": "11.1.0",
34
- "@prisma/debug": "7.3.0-dev.7",
35
- "@prisma/driver-adapter-utils": "7.3.0-dev.7",
36
- "@prisma/client-runtime-utils": "7.3.0-dev.7",
37
- "@prisma/sqlcommenter": "7.3.0-dev.7"
34
+ "@prisma/client-runtime-utils": "7.3.0-dev.9",
35
+ "@prisma/debug": "7.3.0-dev.9",
36
+ "@prisma/driver-adapter-utils": "7.3.0-dev.9",
37
+ "@prisma/sqlcommenter": "7.3.0-dev.9"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@codspeed/benchmark.js-plugin": "4.0.0",