@prisma/adapter-d1 6.15.0-dev.3 → 6.15.0-dev.5

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.js CHANGED
@@ -186,6 +186,46 @@ function mapRow(result, columnTypes) {
186
186
  }
187
187
  return result;
188
188
  }
189
+ function mapArg(arg, argType) {
190
+ if (arg === null) {
191
+ return null;
192
+ }
193
+ if (typeof arg === "bigint" || argType.scalarType === "bigint") {
194
+ const asInt56 = Number.parseInt(`${arg}`);
195
+ if (!Number.isSafeInteger(asInt56)) {
196
+ throw new Error(`Invalid Int64-encoded value received: ${arg}`);
197
+ }
198
+ return asInt56;
199
+ }
200
+ if (typeof arg === "string" && argType.scalarType === "int") {
201
+ return Number.parseInt(arg);
202
+ }
203
+ if (typeof arg === "string" && argType.scalarType === "float") {
204
+ return Number.parseFloat(arg);
205
+ }
206
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
207
+ return Number.parseFloat(arg);
208
+ }
209
+ if (arg === true) {
210
+ return 1;
211
+ }
212
+ if (arg === false) {
213
+ return 0;
214
+ }
215
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
216
+ arg = new Date(arg);
217
+ }
218
+ if (arg instanceof Date) {
219
+ return arg.toISOString().replace("Z", "+00:00");
220
+ }
221
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
222
+ return Array.from(Buffer.from(arg, "base64"));
223
+ }
224
+ if (arg instanceof Uint8Array) {
225
+ return Array.from(arg);
226
+ }
227
+ return arg;
228
+ }
189
229
 
190
230
  // src/errors.ts
191
231
  function convertDriverError(error) {
@@ -243,35 +283,6 @@ function isDriverError(error) {
243
283
  return typeof error["message"] === "string";
244
284
  }
245
285
 
246
- // src/utils.ts
247
- function cleanArg(arg, argType) {
248
- if (arg !== null) {
249
- if (argType === "Int64" || typeof arg === "bigint") {
250
- const asInt56 = Number.parseInt(`${arg}`);
251
- if (!Number.isSafeInteger(asInt56)) {
252
- throw new Error(`Invalid Int64-encoded value received: ${arg}`);
253
- }
254
- return asInt56;
255
- }
256
- if (argType === "Int32") {
257
- return Number.parseInt(arg);
258
- }
259
- if (argType === "Float" || argType === "Double") {
260
- return Number.parseFloat(arg);
261
- }
262
- if (arg === true) {
263
- return 1;
264
- }
265
- if (arg === false) {
266
- return 0;
267
- }
268
- if (arg instanceof Uint8Array) {
269
- return Array.from(arg);
270
- }
271
- }
272
- return arg;
273
- }
274
-
275
286
  // src/d1-http.ts
276
287
  var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:d1-http");
277
288
  function onUnsuccessfulD1HTTPResponse({ errors }) {
@@ -353,11 +364,10 @@ var D1HTTPQueryable = class {
353
364
  }
354
365
  async performIO(query) {
355
366
  try {
356
- query.args = query.args.map((arg, i) => cleanArg(arg, query.argTypes[i]));
357
367
  const body = {
358
368
  json: {
359
369
  sql: query.sql,
360
- params: query.args
370
+ params: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
361
371
  }
362
372
  };
363
373
  const tag = "[js::perform_io]";
@@ -576,8 +586,8 @@ var D1WorkerQueryable = class {
576
586
  }
577
587
  async performIO(query, executeRaw = false) {
578
588
  try {
579
- query.args = query.args.map((arg, i) => cleanArg(arg, query.argTypes[i]));
580
- const stmt = this.client.prepare(query.sql).bind(...query.args);
589
+ const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
590
+ const stmt = this.client.prepare(query.sql).bind(...args);
581
591
  if (executeRaw) {
582
592
  return await stmt.run();
583
593
  } else {
package/dist/index.mjs CHANGED
@@ -152,6 +152,46 @@ function mapRow(result, columnTypes) {
152
152
  }
153
153
  return result;
154
154
  }
155
+ function mapArg(arg, argType) {
156
+ if (arg === null) {
157
+ return null;
158
+ }
159
+ if (typeof arg === "bigint" || argType.scalarType === "bigint") {
160
+ const asInt56 = Number.parseInt(`${arg}`);
161
+ if (!Number.isSafeInteger(asInt56)) {
162
+ throw new Error(`Invalid Int64-encoded value received: ${arg}`);
163
+ }
164
+ return asInt56;
165
+ }
166
+ if (typeof arg === "string" && argType.scalarType === "int") {
167
+ return Number.parseInt(arg);
168
+ }
169
+ if (typeof arg === "string" && argType.scalarType === "float") {
170
+ return Number.parseFloat(arg);
171
+ }
172
+ if (typeof arg === "string" && argType.scalarType === "decimal") {
173
+ return Number.parseFloat(arg);
174
+ }
175
+ if (arg === true) {
176
+ return 1;
177
+ }
178
+ if (arg === false) {
179
+ return 0;
180
+ }
181
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
182
+ arg = new Date(arg);
183
+ }
184
+ if (arg instanceof Date) {
185
+ return arg.toISOString().replace("Z", "+00:00");
186
+ }
187
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
188
+ return Array.from(Buffer.from(arg, "base64"));
189
+ }
190
+ if (arg instanceof Uint8Array) {
191
+ return Array.from(arg);
192
+ }
193
+ return arg;
194
+ }
155
195
 
156
196
  // src/errors.ts
157
197
  function convertDriverError(error) {
@@ -209,35 +249,6 @@ function isDriverError(error) {
209
249
  return typeof error["message"] === "string";
210
250
  }
211
251
 
212
- // src/utils.ts
213
- function cleanArg(arg, argType) {
214
- if (arg !== null) {
215
- if (argType === "Int64" || typeof arg === "bigint") {
216
- const asInt56 = Number.parseInt(`${arg}`);
217
- if (!Number.isSafeInteger(asInt56)) {
218
- throw new Error(`Invalid Int64-encoded value received: ${arg}`);
219
- }
220
- return asInt56;
221
- }
222
- if (argType === "Int32") {
223
- return Number.parseInt(arg);
224
- }
225
- if (argType === "Float" || argType === "Double") {
226
- return Number.parseFloat(arg);
227
- }
228
- if (arg === true) {
229
- return 1;
230
- }
231
- if (arg === false) {
232
- return 0;
233
- }
234
- if (arg instanceof Uint8Array) {
235
- return Array.from(arg);
236
- }
237
- }
238
- return arg;
239
- }
240
-
241
252
  // src/d1-http.ts
242
253
  var debug = Debug("prisma:driver-adapter:d1-http");
243
254
  function onUnsuccessfulD1HTTPResponse({ errors }) {
@@ -319,11 +330,10 @@ var D1HTTPQueryable = class {
319
330
  }
320
331
  async performIO(query) {
321
332
  try {
322
- query.args = query.args.map((arg, i) => cleanArg(arg, query.argTypes[i]));
323
333
  const body = {
324
334
  json: {
325
335
  sql: query.sql,
326
- params: query.args
336
+ params: query.args.map((arg, i) => mapArg(arg, query.argTypes[i]))
327
337
  }
328
338
  };
329
339
  const tag = "[js::perform_io]";
@@ -545,8 +555,8 @@ var D1WorkerQueryable = class {
545
555
  }
546
556
  async performIO(query, executeRaw = false) {
547
557
  try {
548
- query.args = query.args.map((arg, i) => cleanArg(arg, query.argTypes[i]));
549
- const stmt = this.client.prepare(query.sql).bind(...query.args);
558
+ const args = query.args.map((arg, i) => mapArg(arg, query.argTypes[i]));
559
+ const stmt = this.client.prepare(query.sql).bind(...args);
550
560
  if (executeRaw) {
551
561
  return await stmt.run();
552
562
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-d1",
3
- "version": "6.15.0-dev.3",
3
+ "version": "6.15.0-dev.5",
4
4
  "description": "Prisma's driver adapter for Cloudflare D1",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@cloudflare/workers-types": "4.20250214.0",
39
39
  "ky": "1.7.5",
40
- "@prisma/driver-adapter-utils": "6.15.0-dev.3"
40
+ "@prisma/driver-adapter-utils": "6.15.0-dev.5"
41
41
  },
42
42
  "devDependencies": {
43
43
  "vitest": "3.0.9"