@prisma/client-engine-runtime 6.4.0-dev.35 → 6.4.0-dev.37

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.
Files changed (2) hide show
  1. package/dist/index.js +86 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -34,45 +34,94 @@ function renderQueryTemplate({
34
34
  query,
35
35
  params
36
36
  }) {
37
- const flattened = [];
37
+ if (!query.includes(BEGIN_REPEAT)) {
38
+ return { query, params };
39
+ }
40
+ const flattenedParams = [];
38
41
  let lastParamId = 1;
39
42
  let result = "";
40
43
  let templatePos = 0;
44
+ let state = 0 /* Normal */;
45
+ let stateBeforeQuote = 0 /* Normal */;
41
46
  while (templatePos < query.length) {
47
+ const nextChar = query[templatePos];
48
+ if (state === 1 /* Quoted */ && nextChar !== '"') {
49
+ result += nextChar;
50
+ templatePos++;
51
+ continue;
52
+ }
53
+ if (nextChar === '"') {
54
+ if (state === 1 /* Quoted */) {
55
+ state = stateBeforeQuote;
56
+ } else {
57
+ stateBeforeQuote = state;
58
+ state = 1 /* Quoted */;
59
+ }
60
+ result += nextChar;
61
+ templatePos++;
62
+ continue;
63
+ }
42
64
  if (query.slice(templatePos, templatePos + BEGIN_REPEAT.length) === BEGIN_REPEAT) {
65
+ if (state === 2 /* Repeating */) {
66
+ throw new Error("Nested repetition is not allowed");
67
+ }
68
+ state = 2 /* Repeating */;
43
69
  templatePos += BEGIN_REPEAT.length;
44
70
  result += "(";
45
- const paramNum = parseInt(query.slice(templatePos).match(/^\$(\d+)/)?.[1] ?? "0");
46
- const arrParam = params[paramNum - 1];
47
- const expanded = arrParam.map((_, idx) => "$" + (lastParamId + idx)).join(", ");
48
- result += expanded;
49
- flattened.push(...arrParam);
50
- lastParamId += arrParam.length;
51
- templatePos += query.slice(templatePos).indexOf(END_REPEAT) + END_REPEAT.length;
71
+ continue;
72
+ }
73
+ if (query.slice(templatePos, templatePos + END_REPEAT.length) === END_REPEAT) {
74
+ if (state === 0 /* Normal */) {
75
+ throw new Error("Unmatched repetition end");
76
+ }
77
+ state = 0 /* Normal */;
78
+ templatePos += END_REPEAT.length;
52
79
  result += ")";
53
- } else if (query[templatePos] === "$") {
80
+ continue;
81
+ }
82
+ if (nextChar === "$") {
54
83
  const paramMatch = query.slice(templatePos + 1).match(/^\d+/);
55
- if (paramMatch) {
56
- const paramNum = parseInt(paramMatch[0]);
57
- const paramValue = params[paramNum - 1];
58
- if (!Array.isArray(paramValue)) {
59
- result += "$" + lastParamId;
60
- flattened.push(paramValue);
61
- lastParamId++;
62
- templatePos += paramMatch[0].length + 1;
63
- }
64
- } else {
65
- result += query[templatePos];
84
+ if (!paramMatch) {
85
+ result += "$";
66
86
  templatePos++;
87
+ continue;
67
88
  }
68
- } else {
69
- result += query[templatePos];
70
- templatePos++;
89
+ templatePos += paramMatch[0].length + 1;
90
+ const originalParamIdx = parseInt(paramMatch[0]);
91
+ const paramValue = params[originalParamIdx - 1];
92
+ switch (state) {
93
+ case 0 /* Normal */: {
94
+ flattenedParams.push(paramValue);
95
+ result += `$${lastParamId++}`;
96
+ break;
97
+ }
98
+ case 2 /* Repeating */: {
99
+ const paramArray = Array.isArray(paramValue) ? paramValue : [paramValue];
100
+ if (paramArray.length === 0) {
101
+ result += "NULL";
102
+ break;
103
+ }
104
+ paramArray.forEach((value, idx) => {
105
+ flattenedParams.push(value);
106
+ result += `$${lastParamId++}`;
107
+ if (idx !== paramArray.length - 1) {
108
+ result += ", ";
109
+ }
110
+ });
111
+ break;
112
+ }
113
+ default: {
114
+ throw new Error(`Unexpected state: ${state}`);
115
+ }
116
+ }
117
+ continue;
71
118
  }
119
+ result += nextChar;
120
+ templatePos++;
72
121
  }
73
122
  return {
74
123
  query: result,
75
- params: flattened
124
+ params: flattenedParams
76
125
  };
77
126
  }
78
127
 
@@ -142,7 +191,19 @@ function placeholderTypeToArgType(type) {
142
191
  function serialize(resultSet) {
143
192
  return resultSet.rows.map(
144
193
  (row) => row.reduce((acc, value, index) => {
145
- acc[resultSet.columnNames[index]] = value;
194
+ const splitByDot = resultSet.columnNames[index].split(".");
195
+ let nested = acc;
196
+ for (let i = 0; i < splitByDot.length; i++) {
197
+ const key = splitByDot[i];
198
+ if (i === splitByDot.length - 1) {
199
+ nested[key] = value;
200
+ } else {
201
+ if (nested[key] === void 0) {
202
+ nested[key] = {};
203
+ }
204
+ nested = nested[key];
205
+ }
206
+ }
146
207
  return acc;
147
208
  }, {})
148
209
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.4.0-dev.35",
3
+ "version": "6.4.0-dev.37",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",