@prisma/client-engine-runtime 7.2.0 → 7.3.0-dev.10
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 +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +36 -18
- package/dist/index.mjs +36 -18
- package/dist/sql-commenter.d.ts +4 -1
- package/dist/tracing.d.ts +1 -0
- package/package.json +9 -5
package/dist/index.d.mts
CHANGED
|
@@ -17,6 +17,9 @@ import { Transaction } from '@prisma/driver-adapter-utils';
|
|
|
17
17
|
/**
|
|
18
18
|
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
19
|
* Keys with undefined values are filtered out.
|
|
20
|
+
*
|
|
21
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
22
|
+
* that could affect other plugins.
|
|
20
23
|
*/
|
|
21
24
|
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
22
25
|
|
|
@@ -444,6 +447,7 @@ export declare type SchemaProvider = 'cockroachdb' | 'mongodb' | 'mysql' | 'post
|
|
|
444
447
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
445
448
|
|
|
446
449
|
export declare interface TracingHelper {
|
|
450
|
+
isEnabled(): boolean;
|
|
447
451
|
runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
|
|
448
452
|
}
|
|
449
453
|
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ import { Transaction } from '@prisma/driver-adapter-utils';
|
|
|
17
17
|
/**
|
|
18
18
|
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
19
19
|
* Keys with undefined values are filtered out.
|
|
20
|
+
*
|
|
21
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
22
|
+
* that could affect other plugins.
|
|
20
23
|
*/
|
|
21
24
|
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
22
25
|
|
|
@@ -444,6 +447,7 @@ export declare type SchemaProvider = 'cockroachdb' | 'mongodb' | 'mysql' | 'post
|
|
|
444
447
|
declare type SpanCallback<R> = (span?: Span, context?: Context) => R;
|
|
445
448
|
|
|
446
449
|
export declare interface TracingHelper {
|
|
450
|
+
isEnabled(): boolean;
|
|
447
451
|
runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
|
|
448
452
|
}
|
|
449
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
|
|
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
|
-
|
|
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 =
|
|
516
|
-
result[name] = mapArrayOrObject(target,
|
|
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":
|
|
@@ -700,6 +710,7 @@ function normalizeDateTime(dt) {
|
|
|
700
710
|
}
|
|
701
711
|
|
|
702
712
|
// src/sql-commenter.ts
|
|
713
|
+
var import_klona = require("klona");
|
|
703
714
|
function formatSqlComment(tags) {
|
|
704
715
|
const entries = Object.entries(tags);
|
|
705
716
|
if (entries.length === 0) {
|
|
@@ -716,7 +727,7 @@ function formatSqlComment(tags) {
|
|
|
716
727
|
function applySqlCommenters(plugins, context) {
|
|
717
728
|
const merged = {};
|
|
718
729
|
for (const plugin of plugins) {
|
|
719
|
-
const tags = plugin(context);
|
|
730
|
+
const tags = plugin((0, import_klona.klona)(context));
|
|
720
731
|
for (const [key, value] of Object.entries(tags)) {
|
|
721
732
|
if (value !== void 0) {
|
|
722
733
|
merged[key] = value;
|
|
@@ -739,6 +750,9 @@ function appendSqlComment(sql, comment) {
|
|
|
739
750
|
// src/tracing.ts
|
|
740
751
|
var import_api = require("@opentelemetry/api");
|
|
741
752
|
var noopTracingHelper = {
|
|
753
|
+
isEnabled() {
|
|
754
|
+
return false;
|
|
755
|
+
},
|
|
742
756
|
runInChildSpan(_, callback) {
|
|
743
757
|
return callback();
|
|
744
758
|
}
|
|
@@ -767,6 +781,22 @@ async function withQuerySpanAndEvent({
|
|
|
767
781
|
onQuery,
|
|
768
782
|
execute
|
|
769
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
|
+
}
|
|
770
800
|
return await tracingHelper.runInChildSpan(
|
|
771
801
|
{
|
|
772
802
|
name: "db_query",
|
|
@@ -776,19 +806,7 @@ async function withQuerySpanAndEvent({
|
|
|
776
806
|
"db.system.name": providerToOtelSystem(provider)
|
|
777
807
|
}
|
|
778
808
|
},
|
|
779
|
-
|
|
780
|
-
const timestamp = /* @__PURE__ */ new Date();
|
|
781
|
-
const startInstant = performance.now();
|
|
782
|
-
const result = await execute();
|
|
783
|
-
const endInstant = performance.now();
|
|
784
|
-
onQuery?.({
|
|
785
|
-
timestamp,
|
|
786
|
-
duration: endInstant - startInstant,
|
|
787
|
-
query: query.sql,
|
|
788
|
-
params: query.args
|
|
789
|
-
});
|
|
790
|
-
return result;
|
|
791
|
-
}
|
|
809
|
+
callback
|
|
792
810
|
);
|
|
793
811
|
}
|
|
794
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
|
|
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
|
-
|
|
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 =
|
|
465
|
-
result[name] = mapArrayOrObject(target,
|
|
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":
|
|
@@ -649,6 +659,7 @@ function normalizeDateTime(dt) {
|
|
|
649
659
|
}
|
|
650
660
|
|
|
651
661
|
// src/sql-commenter.ts
|
|
662
|
+
import { klona } from "klona";
|
|
652
663
|
function formatSqlComment(tags) {
|
|
653
664
|
const entries = Object.entries(tags);
|
|
654
665
|
if (entries.length === 0) {
|
|
@@ -665,7 +676,7 @@ function formatSqlComment(tags) {
|
|
|
665
676
|
function applySqlCommenters(plugins, context) {
|
|
666
677
|
const merged = {};
|
|
667
678
|
for (const plugin of plugins) {
|
|
668
|
-
const tags = plugin(context);
|
|
679
|
+
const tags = plugin(klona(context));
|
|
669
680
|
for (const [key, value] of Object.entries(tags)) {
|
|
670
681
|
if (value !== void 0) {
|
|
671
682
|
merged[key] = value;
|
|
@@ -688,6 +699,9 @@ function appendSqlComment(sql, comment) {
|
|
|
688
699
|
// src/tracing.ts
|
|
689
700
|
import { SpanKind } from "@opentelemetry/api";
|
|
690
701
|
var noopTracingHelper = {
|
|
702
|
+
isEnabled() {
|
|
703
|
+
return false;
|
|
704
|
+
},
|
|
691
705
|
runInChildSpan(_, callback) {
|
|
692
706
|
return callback();
|
|
693
707
|
}
|
|
@@ -716,6 +730,22 @@ async function withQuerySpanAndEvent({
|
|
|
716
730
|
onQuery,
|
|
717
731
|
execute
|
|
718
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
|
+
}
|
|
719
749
|
return await tracingHelper.runInChildSpan(
|
|
720
750
|
{
|
|
721
751
|
name: "db_query",
|
|
@@ -725,19 +755,7 @@ async function withQuerySpanAndEvent({
|
|
|
725
755
|
"db.system.name": providerToOtelSystem(provider)
|
|
726
756
|
}
|
|
727
757
|
},
|
|
728
|
-
|
|
729
|
-
const timestamp = /* @__PURE__ */ new Date();
|
|
730
|
-
const startInstant = performance.now();
|
|
731
|
-
const result = await execute();
|
|
732
|
-
const endInstant = performance.now();
|
|
733
|
-
onQuery?.({
|
|
734
|
-
timestamp,
|
|
735
|
-
duration: endInstant - startInstant,
|
|
736
|
-
query: query.sql,
|
|
737
|
-
params: query.args
|
|
738
|
-
});
|
|
739
|
-
return result;
|
|
740
|
-
}
|
|
758
|
+
callback
|
|
741
759
|
);
|
|
742
760
|
}
|
|
743
761
|
|
package/dist/sql-commenter.d.ts
CHANGED
|
@@ -10,12 +10,15 @@ import type { SqlCommenterContext, SqlCommenterPlugin } from '@prisma/sqlcomment
|
|
|
10
10
|
* 5. Replace ' with \' in values (after URL encoding)
|
|
11
11
|
* 6. Wrap values in single quotes
|
|
12
12
|
* 7. Join key='value' pairs with commas
|
|
13
|
-
* 8. Wrap in
|
|
13
|
+
* 8. Wrap in a SQL comment
|
|
14
14
|
*/
|
|
15
15
|
export declare function formatSqlComment(tags: Record<string, string>): string;
|
|
16
16
|
/**
|
|
17
17
|
* Applies SQL commenter plugins and returns the merged key-value pairs.
|
|
18
18
|
* Keys with undefined values are filtered out.
|
|
19
|
+
*
|
|
20
|
+
* Each plugin receives a deep clone of the context to prevent mutations
|
|
21
|
+
* that could affect other plugins.
|
|
19
22
|
*/
|
|
20
23
|
export declare function applySqlCommenters(plugins: SqlCommenterPlugin[], context: SqlCommenterContext): Record<string, string>;
|
|
21
24
|
/**
|
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
|
+
"version": "7.3.0-dev.10",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,17 +27,21 @@
|
|
|
27
27
|
"@bugsnag/cuid": "3.2.1",
|
|
28
28
|
"@opentelemetry/api": "1.9.0",
|
|
29
29
|
"@paralleldrive/cuid2": "2.2.2",
|
|
30
|
+
"klona": "2.0.6",
|
|
30
31
|
"nanoid": "5.1.5",
|
|
31
32
|
"ulid": "3.0.0",
|
|
32
33
|
"uuid": "11.1.0",
|
|
33
|
-
"@prisma/client-runtime-utils": "7.
|
|
34
|
-
"@prisma/debug": "7.
|
|
35
|
-
"@prisma/
|
|
36
|
-
"@prisma/
|
|
34
|
+
"@prisma/client-runtime-utils": "7.3.0-dev.10",
|
|
35
|
+
"@prisma/debug": "7.3.0-dev.10",
|
|
36
|
+
"@prisma/sqlcommenter": "7.3.0-dev.10",
|
|
37
|
+
"@prisma/driver-adapter-utils": "7.3.0-dev.10"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@codspeed/benchmark.js-plugin": "4.0.0",
|
|
41
|
+
"@types/benchmark": "2.1.5",
|
|
39
42
|
"@types/jest": "29.5.14",
|
|
40
43
|
"@types/node": "~20.19.24",
|
|
44
|
+
"benchmark": "2.1.4",
|
|
41
45
|
"jest": "29.7.0",
|
|
42
46
|
"jest-junit": "16.0.0"
|
|
43
47
|
},
|