@prisma/client-engine-runtime 6.6.0-dev.68 → 6.6.0-dev.69

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.
@@ -12,9 +12,27 @@ export type QueryPlanBinding = {
12
12
  expr: QueryPlanNode;
13
13
  };
14
14
  export type QueryPlanDbQuery = {
15
- query: string;
15
+ type: 'rawSql';
16
+ sql: string;
16
17
  params: PrismaValue[];
18
+ } | {
19
+ type: 'templateSql';
20
+ fragments: Fragment[];
21
+ placeholderFormat: PlaceholderFormat;
22
+ params: PrismaValue[];
23
+ };
24
+ export type Fragment = {
25
+ type: 'stringChunk';
26
+ value: string;
27
+ } | {
28
+ type: 'parameter';
29
+ } | {
30
+ type: 'parameterTuple';
17
31
  };
32
+ export interface PlaceholderFormat {
33
+ prefix: string;
34
+ hasNumbering: boolean;
35
+ }
18
36
  export type JoinExpression = {
19
37
  child: QueryPlanNode;
20
38
  on: [left: string, right: string][];
package/dist/index.d.mts CHANGED
@@ -3,6 +3,15 @@ import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
3
  import { SqlQueryable } from '@prisma/driver-adapter-utils';
4
4
  import { Transaction } from '@prisma/driver-adapter-utils';
5
5
 
6
+ export declare type Fragment = {
7
+ type: 'stringChunk';
8
+ value: string;
9
+ } | {
10
+ type: 'parameter';
11
+ } | {
12
+ type: 'parameterTuple';
13
+ };
14
+
6
15
  export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
7
16
 
8
17
  export declare type JoinExpression = {
@@ -11,6 +20,11 @@ export declare type JoinExpression = {
11
20
  parentField: string;
12
21
  };
13
22
 
23
+ export declare interface PlaceholderFormat {
24
+ prefix: string;
25
+ hasNumbering: boolean;
26
+ }
27
+
14
28
  export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder;
15
29
 
16
30
  export declare type PrismaValuePlaceholder = {
@@ -47,7 +61,13 @@ export declare type QueryPlanBinding = {
47
61
  };
48
62
 
49
63
  export declare type QueryPlanDbQuery = {
50
- query: string;
64
+ type: 'rawSql';
65
+ sql: string;
66
+ params: PrismaValue[];
67
+ } | {
68
+ type: 'templateSql';
69
+ fragments: Fragment[];
70
+ placeholderFormat: PlaceholderFormat;
51
71
  params: PrismaValue[];
52
72
  };
53
73
 
package/dist/index.d.ts CHANGED
@@ -3,6 +3,15 @@ import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
3
  import { SqlQueryable } from '@prisma/driver-adapter-utils';
4
4
  import { Transaction } from '@prisma/driver-adapter-utils';
5
5
 
6
+ export declare type Fragment = {
7
+ type: 'stringChunk';
8
+ value: string;
9
+ } | {
10
+ type: 'parameter';
11
+ } | {
12
+ type: 'parameterTuple';
13
+ };
14
+
6
15
  export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
7
16
 
8
17
  export declare type JoinExpression = {
@@ -11,6 +20,11 @@ export declare type JoinExpression = {
11
20
  parentField: string;
12
21
  };
13
22
 
23
+ export declare interface PlaceholderFormat {
24
+ prefix: string;
25
+ hasNumbering: boolean;
26
+ }
27
+
14
28
  export declare type PrismaValue = string | boolean | number | PrismaValue[] | null | Record<string, unknown> | PrismaValuePlaceholder;
15
29
 
16
30
  export declare type PrismaValuePlaceholder = {
@@ -47,7 +61,13 @@ export declare type QueryPlanBinding = {
47
61
  };
48
62
 
49
63
  export declare type QueryPlanDbQuery = {
50
- query: string;
64
+ type: 'rawSql';
65
+ sql: string;
66
+ params: PrismaValue[];
67
+ } | {
68
+ type: 'templateSql';
69
+ fragments: Fragment[];
70
+ placeholderFormat: PlaceholderFormat;
51
71
  params: PrismaValue[];
52
72
  };
53
73
 
package/dist/index.js CHANGED
@@ -42,107 +42,25 @@ function isPrismaValuePlaceholder(value) {
42
42
  return typeof value === "object" && value !== null && value["prisma__type"] === "param";
43
43
  }
44
44
 
45
- // src/interpreter/renderQueryTemplate.ts
46
- var BEGIN_REPEAT = "/* prisma-comma-repeatable-start */";
47
- var END_REPEAT = "/* prisma-comma-repeatable-end */";
48
- function renderQueryTemplate({
49
- query,
50
- params
51
- }) {
52
- if (!query.includes(BEGIN_REPEAT)) {
53
- return { query, params };
54
- }
55
- const flattenedParams = [];
56
- let lastParamId = 1;
57
- let result = "";
58
- let templatePos = 0;
59
- let state = 0 /* Normal */;
60
- let stateBeforeQuote = 0 /* Normal */;
61
- while (templatePos < query.length) {
62
- const nextChar = query[templatePos];
63
- if (state === 1 /* Quoted */ && nextChar !== '"') {
64
- result += nextChar;
65
- templatePos++;
66
- continue;
67
- }
68
- if (nextChar === '"') {
69
- if (state === 1 /* Quoted */) {
70
- state = stateBeforeQuote;
71
- } else {
72
- stateBeforeQuote = state;
73
- state = 1 /* Quoted */;
74
- }
75
- result += nextChar;
76
- templatePos++;
77
- continue;
78
- }
79
- if (query.slice(templatePos, templatePos + BEGIN_REPEAT.length) === BEGIN_REPEAT) {
80
- if (state === 2 /* Repeating */) {
81
- throw new Error("Nested repetition is not allowed");
82
- }
83
- state = 2 /* Repeating */;
84
- templatePos += BEGIN_REPEAT.length;
85
- result += "(";
86
- continue;
87
- }
88
- if (query.slice(templatePos, templatePos + END_REPEAT.length) === END_REPEAT) {
89
- if (state === 0 /* Normal */) {
90
- throw new Error("Unmatched repetition end");
91
- }
92
- state = 0 /* Normal */;
93
- templatePos += END_REPEAT.length;
94
- result += ")";
95
- continue;
96
- }
97
- if (nextChar === "$") {
98
- const paramMatch = query.slice(templatePos + 1).match(/^\d+/);
99
- if (!paramMatch) {
100
- result += "$";
101
- templatePos++;
102
- continue;
103
- }
104
- templatePos += paramMatch[0].length + 1;
105
- const originalParamIdx = parseInt(paramMatch[0]);
106
- const paramValue = params[originalParamIdx - 1];
107
- switch (state) {
108
- case 0 /* Normal */: {
109
- flattenedParams.push(paramValue);
110
- result += `$${lastParamId++}`;
111
- break;
112
- }
113
- case 2 /* Repeating */: {
114
- const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
115
- if (paramArray.length === 0) {
116
- result += "NULL";
117
- break;
118
- }
119
- paramArray.forEach((value, idx) => {
120
- flattenedParams.push(value);
121
- result += `$${lastParamId++}`;
122
- if (idx !== paramArray.length - 1) {
123
- result += ", ";
124
- }
125
- });
126
- break;
127
- }
128
- default: {
129
- throw new Error(`Unexpected state: ${state}`);
130
- }
131
- }
132
- continue;
133
- }
134
- result += nextChar;
135
- templatePos++;
136
- }
137
- return {
138
- query: result,
139
- params: flattenedParams
140
- };
45
+ // src/utils.ts
46
+ function assertNever(_, message) {
47
+ throw new Error(message);
141
48
  }
142
49
 
143
50
  // src/interpreter/renderQuery.ts
144
- function renderQuery({ query, params }, scope) {
145
- const substitutedParams = params.map((param) => {
51
+ function renderQuery(dbQuery, scope) {
52
+ const queryType = dbQuery.type;
53
+ switch (queryType) {
54
+ case "rawSql":
55
+ return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope));
56
+ case "templateSql":
57
+ return renderTemplateSql(dbQuery.fragments, dbQuery.placeholderFormat, substituteParams(dbQuery.params, scope));
58
+ default:
59
+ assertNever(queryType, `Invalid query type`);
60
+ }
61
+ }
62
+ function substituteParams(params, scope) {
63
+ return params.map((param) => {
146
64
  if (!isPrismaValuePlaceholder(param)) {
147
65
  return param;
148
66
  }
@@ -152,11 +70,48 @@ function renderQuery({ query, params }, scope) {
152
70
  }
153
71
  return value;
154
72
  });
155
- const { query: renderedQuery, params: expandedParams } = renderQueryTemplate({ query, params: substitutedParams });
156
- const argTypes = expandedParams.map((param) => toArgType(param));
73
+ }
74
+ function renderTemplateSql(fragments, placeholderFormat, params) {
75
+ let paramIndex = 0;
76
+ let placeholderNumber = 1;
77
+ const flattenedParams = [];
78
+ const sql = fragments.map((fragment) => {
79
+ const fragmentType = fragment.type;
80
+ switch (fragmentType) {
81
+ case "parameter":
82
+ if (paramIndex >= params.length) {
83
+ throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
84
+ }
85
+ flattenedParams.push(params[paramIndex++]);
86
+ return formatPlaceholder(placeholderFormat, placeholderNumber++);
87
+ case "stringChunk":
88
+ return fragment.value;
89
+ case "parameterTuple": {
90
+ if (paramIndex >= params.length) {
91
+ throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
92
+ }
93
+ const paramValue = params[paramIndex++];
94
+ const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
95
+ const placeholders = paramArray.length == 0 ? "NULL" : paramArray.map((value) => {
96
+ flattenedParams.push(value);
97
+ return formatPlaceholder(placeholderFormat, placeholderNumber++);
98
+ }).join(",");
99
+ return `(${placeholders})`;
100
+ }
101
+ default:
102
+ assertNever(fragmentType, "Invalid fragment type");
103
+ }
104
+ }).join("");
105
+ return renderRawSql(sql, flattenedParams);
106
+ }
107
+ function formatPlaceholder(placeholderFormat, placeholderNumber) {
108
+ return placeholderFormat.hasNumbering ? `${placeholderFormat.prefix}${placeholderNumber}` : placeholderFormat.prefix;
109
+ }
110
+ function renderRawSql(sql, params) {
111
+ const argTypes = params.map((param) => toArgType(param));
157
112
  return {
158
- sql: renderedQuery,
159
- args: expandedParams,
113
+ sql,
114
+ args: params,
160
115
  argTypes
161
116
  };
162
117
  }
@@ -413,11 +368,6 @@ async function randomUUID() {
413
368
  return crypto.randomUUID();
414
369
  }
415
370
 
416
- // src/utils.ts
417
- function assertNever(_, message) {
418
- throw new Error(message);
419
- }
420
-
421
371
  // src/transactionManager/TransactionManagerErrors.ts
422
372
  var TransactionManagerError = class extends Error {
423
373
  constructor(message, meta) {
package/dist/index.mjs CHANGED
@@ -3,107 +3,25 @@ function isPrismaValuePlaceholder(value) {
3
3
  return typeof value === "object" && value !== null && value["prisma__type"] === "param";
4
4
  }
5
5
 
6
- // src/interpreter/renderQueryTemplate.ts
7
- var BEGIN_REPEAT = "/* prisma-comma-repeatable-start */";
8
- var END_REPEAT = "/* prisma-comma-repeatable-end */";
9
- function renderQueryTemplate({
10
- query,
11
- params
12
- }) {
13
- if (!query.includes(BEGIN_REPEAT)) {
14
- return { query, params };
15
- }
16
- const flattenedParams = [];
17
- let lastParamId = 1;
18
- let result = "";
19
- let templatePos = 0;
20
- let state = 0 /* Normal */;
21
- let stateBeforeQuote = 0 /* Normal */;
22
- while (templatePos < query.length) {
23
- const nextChar = query[templatePos];
24
- if (state === 1 /* Quoted */ && nextChar !== '"') {
25
- result += nextChar;
26
- templatePos++;
27
- continue;
28
- }
29
- if (nextChar === '"') {
30
- if (state === 1 /* Quoted */) {
31
- state = stateBeforeQuote;
32
- } else {
33
- stateBeforeQuote = state;
34
- state = 1 /* Quoted */;
35
- }
36
- result += nextChar;
37
- templatePos++;
38
- continue;
39
- }
40
- if (query.slice(templatePos, templatePos + BEGIN_REPEAT.length) === BEGIN_REPEAT) {
41
- if (state === 2 /* Repeating */) {
42
- throw new Error("Nested repetition is not allowed");
43
- }
44
- state = 2 /* Repeating */;
45
- templatePos += BEGIN_REPEAT.length;
46
- result += "(";
47
- continue;
48
- }
49
- if (query.slice(templatePos, templatePos + END_REPEAT.length) === END_REPEAT) {
50
- if (state === 0 /* Normal */) {
51
- throw new Error("Unmatched repetition end");
52
- }
53
- state = 0 /* Normal */;
54
- templatePos += END_REPEAT.length;
55
- result += ")";
56
- continue;
57
- }
58
- if (nextChar === "$") {
59
- const paramMatch = query.slice(templatePos + 1).match(/^\d+/);
60
- if (!paramMatch) {
61
- result += "$";
62
- templatePos++;
63
- continue;
64
- }
65
- templatePos += paramMatch[0].length + 1;
66
- const originalParamIdx = parseInt(paramMatch[0]);
67
- const paramValue = params[originalParamIdx - 1];
68
- switch (state) {
69
- case 0 /* Normal */: {
70
- flattenedParams.push(paramValue);
71
- result += `$${lastParamId++}`;
72
- break;
73
- }
74
- case 2 /* Repeating */: {
75
- const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
76
- if (paramArray.length === 0) {
77
- result += "NULL";
78
- break;
79
- }
80
- paramArray.forEach((value, idx) => {
81
- flattenedParams.push(value);
82
- result += `$${lastParamId++}`;
83
- if (idx !== paramArray.length - 1) {
84
- result += ", ";
85
- }
86
- });
87
- break;
88
- }
89
- default: {
90
- throw new Error(`Unexpected state: ${state}`);
91
- }
92
- }
93
- continue;
94
- }
95
- result += nextChar;
96
- templatePos++;
97
- }
98
- return {
99
- query: result,
100
- params: flattenedParams
101
- };
6
+ // src/utils.ts
7
+ function assertNever(_, message) {
8
+ throw new Error(message);
102
9
  }
103
10
 
104
11
  // src/interpreter/renderQuery.ts
105
- function renderQuery({ query, params }, scope) {
106
- const substitutedParams = params.map((param) => {
12
+ function renderQuery(dbQuery, scope) {
13
+ const queryType = dbQuery.type;
14
+ switch (queryType) {
15
+ case "rawSql":
16
+ return renderRawSql(dbQuery.sql, substituteParams(dbQuery.params, scope));
17
+ case "templateSql":
18
+ return renderTemplateSql(dbQuery.fragments, dbQuery.placeholderFormat, substituteParams(dbQuery.params, scope));
19
+ default:
20
+ assertNever(queryType, `Invalid query type`);
21
+ }
22
+ }
23
+ function substituteParams(params, scope) {
24
+ return params.map((param) => {
107
25
  if (!isPrismaValuePlaceholder(param)) {
108
26
  return param;
109
27
  }
@@ -113,11 +31,48 @@ function renderQuery({ query, params }, scope) {
113
31
  }
114
32
  return value;
115
33
  });
116
- const { query: renderedQuery, params: expandedParams } = renderQueryTemplate({ query, params: substitutedParams });
117
- const argTypes = expandedParams.map((param) => toArgType(param));
34
+ }
35
+ function renderTemplateSql(fragments, placeholderFormat, params) {
36
+ let paramIndex = 0;
37
+ let placeholderNumber = 1;
38
+ const flattenedParams = [];
39
+ const sql = fragments.map((fragment) => {
40
+ const fragmentType = fragment.type;
41
+ switch (fragmentType) {
42
+ case "parameter":
43
+ if (paramIndex >= params.length) {
44
+ throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
45
+ }
46
+ flattenedParams.push(params[paramIndex++]);
47
+ return formatPlaceholder(placeholderFormat, placeholderNumber++);
48
+ case "stringChunk":
49
+ return fragment.value;
50
+ case "parameterTuple": {
51
+ if (paramIndex >= params.length) {
52
+ throw new Error(`Malformed query template. Fragments attempt to read over ${params.length} parameters.`);
53
+ }
54
+ const paramValue = params[paramIndex++];
55
+ const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
56
+ const placeholders = paramArray.length == 0 ? "NULL" : paramArray.map((value) => {
57
+ flattenedParams.push(value);
58
+ return formatPlaceholder(placeholderFormat, placeholderNumber++);
59
+ }).join(",");
60
+ return `(${placeholders})`;
61
+ }
62
+ default:
63
+ assertNever(fragmentType, "Invalid fragment type");
64
+ }
65
+ }).join("");
66
+ return renderRawSql(sql, flattenedParams);
67
+ }
68
+ function formatPlaceholder(placeholderFormat, placeholderNumber) {
69
+ return placeholderFormat.hasNumbering ? `${placeholderFormat.prefix}${placeholderNumber}` : placeholderFormat.prefix;
70
+ }
71
+ function renderRawSql(sql, params) {
72
+ const argTypes = params.map((param) => toArgType(param));
118
73
  return {
119
- sql: renderedQuery,
120
- args: expandedParams,
74
+ sql,
75
+ args: params,
121
76
  argTypes
122
77
  };
123
78
  }
@@ -374,11 +329,6 @@ async function randomUUID() {
374
329
  return crypto.randomUUID();
375
330
  }
376
331
 
377
- // src/utils.ts
378
- function assertNever(_, message) {
379
- throw new Error(message);
380
- }
381
-
382
332
  // src/transactionManager/TransactionManagerErrors.ts
383
333
  var TransactionManagerError = class extends Error {
384
334
  constructor(message, meta) {
@@ -1,4 +1,4 @@
1
1
  import { SqlQuery } from '@prisma/driver-adapter-utils';
2
- import { QueryPlanDbQuery } from '../QueryPlan';
2
+ import type { QueryPlanDbQuery } from '../QueryPlan';
3
3
  import { ScopeBindings } from './scope';
4
- export declare function renderQuery({ query, params }: QueryPlanDbQuery, scope: ScopeBindings): SqlQuery;
4
+ export declare function renderQuery(dbQuery: QueryPlanDbQuery, scope: ScopeBindings): SqlQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.6.0-dev.68",
3
+ "version": "6.6.0-dev.69",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -24,8 +24,8 @@
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "@prisma/debug": "6.6.0-dev.68",
28
- "@prisma/driver-adapter-utils": "6.6.0-dev.68"
27
+ "@prisma/debug": "6.6.0-dev.69",
28
+ "@prisma/driver-adapter-utils": "6.6.0-dev.69"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/jest": "29.5.14",
@@ -1,10 +0,0 @@
1
- import { Value } from './scope';
2
- /**
3
- * A `QueryPlanDbQuery` in which all placeholders have been substituted with
4
- * their values from the environment.
5
- */
6
- export type QueryWithSubstitutedPlaceholders = {
7
- query: string;
8
- params: Value[];
9
- };
10
- export declare function renderQueryTemplate({ query, params, }: QueryWithSubstitutedPlaceholders): QueryWithSubstitutedPlaceholders;