@tursodatabase/serverless 1.1.0 → 1.1.1

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.
@@ -11,7 +11,7 @@ export interface ExecuteResult {
11
11
  cols: Column[];
12
12
  rows: Value[][];
13
13
  affected_row_count: number;
14
- last_insert_rowid?: string;
14
+ last_insert_rowid?: string | number;
15
15
  }
16
16
  export interface NamedArg {
17
17
  name: string;
@@ -100,7 +100,7 @@ export interface CursorEntry {
100
100
  cols?: Column[];
101
101
  row?: Value[];
102
102
  affected_row_count?: number;
103
- last_insert_rowid?: string;
103
+ last_insert_rowid?: string | number;
104
104
  error?: {
105
105
  message: string;
106
106
  code: string;
package/dist/protocol.js CHANGED
@@ -7,6 +7,9 @@ export function encodeValue(value) {
7
7
  if (!Number.isFinite(value)) {
8
8
  throw new Error("Only finite numbers (not Infinity or NaN) can be passed as arguments");
9
9
  }
10
+ if (Number.isInteger(value)) {
11
+ return { type: 'integer', value: value.toString() };
12
+ }
10
13
  return { type: 'float', value };
11
14
  }
12
15
  if (typeof value === 'bigint') {
@@ -38,8 +41,12 @@ export function decodeValue(value, safeIntegers = false) {
38
41
  case 'text':
39
42
  return value.value;
40
43
  case 'blob':
41
- if (value.base64) {
42
- const binaryString = atob(value.base64);
44
+ if (value.base64 !== undefined && value.base64 !== null) {
45
+ let b64 = value.base64;
46
+ while (b64.length % 4 !== 0) {
47
+ b64 += '=';
48
+ }
49
+ const binaryString = atob(b64);
43
50
  const bytes = new Uint8Array(binaryString.length);
44
51
  for (let i = 0; i < binaryString.length; i++) {
45
52
  bytes[i] = binaryString.charCodeAt(i);
package/dist/session.js CHANGED
@@ -39,7 +39,14 @@ export class Session {
39
39
  sql: sql
40
40
  }]
41
41
  };
42
- const response = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
42
+ let response;
43
+ try {
44
+ response = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
45
+ }
46
+ catch (e) {
47
+ this.baton = null;
48
+ throw e;
49
+ }
43
50
  this.baton = response.baton;
44
51
  if (response.base_url) {
45
52
  this.baseUrl = response.base_url;
@@ -125,7 +132,15 @@ export class Session {
125
132
  }]
126
133
  }
127
134
  };
128
- const { response, entries } = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
135
+ let result;
136
+ try {
137
+ result = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
138
+ }
139
+ catch (e) {
140
+ this.baton = null;
141
+ throw e;
142
+ }
143
+ const { response, entries } = result;
129
144
  this.baton = response.baton;
130
145
  if (response.base_url) {
131
146
  this.baseUrl = response.base_url;
@@ -163,8 +178,10 @@ export class Session {
163
178
  if (entry.affected_row_count !== undefined) {
164
179
  rowsAffected = entry.affected_row_count;
165
180
  }
166
- if (entry.last_insert_rowid) {
167
- lastInsertRowid = parseInt(entry.last_insert_rowid, 10);
181
+ if (entry.last_insert_rowid !== undefined && entry.last_insert_rowid !== null) {
182
+ lastInsertRowid = typeof entry.last_insert_rowid === 'number'
183
+ ? entry.last_insert_rowid
184
+ : parseInt(entry.last_insert_rowid, 10);
168
185
  }
169
186
  break;
170
187
  case 'step_error':
@@ -223,7 +240,15 @@ export class Session {
223
240
  }))
224
241
  }
225
242
  };
226
- const { response, entries } = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
243
+ let batchResult;
244
+ try {
245
+ batchResult = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
246
+ }
247
+ catch (e) {
248
+ this.baton = null;
249
+ throw e;
250
+ }
251
+ const { response, entries } = batchResult;
227
252
  this.baton = response.baton;
228
253
  if (response.base_url) {
229
254
  this.baseUrl = response.base_url;
@@ -236,8 +261,10 @@ export class Session {
236
261
  if (entry.affected_row_count !== undefined) {
237
262
  totalRowsAffected += entry.affected_row_count;
238
263
  }
239
- if (entry.last_insert_rowid) {
240
- lastInsertRowid = parseInt(entry.last_insert_rowid, 10);
264
+ if (entry.last_insert_rowid !== undefined && entry.last_insert_rowid !== null) {
265
+ lastInsertRowid = typeof entry.last_insert_rowid === 'number'
266
+ ? entry.last_insert_rowid
267
+ : parseInt(entry.last_insert_rowid, 10);
241
268
  }
242
269
  break;
243
270
  case 'step_error':
@@ -264,14 +291,21 @@ export class Session {
264
291
  sql: sql
265
292
  }]
266
293
  };
267
- const response = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
268
- this.baton = response.baton;
269
- if (response.base_url) {
270
- this.baseUrl = response.base_url;
294
+ let seqResponse;
295
+ try {
296
+ seqResponse = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
297
+ }
298
+ catch (e) {
299
+ this.baton = null;
300
+ throw e;
301
+ }
302
+ this.baton = seqResponse.baton;
303
+ if (seqResponse.base_url) {
304
+ this.baseUrl = seqResponse.base_url;
271
305
  }
272
306
  // Check for errors in the response
273
- if (response.results && response.results[0]) {
274
- const result = response.results[0];
307
+ if (seqResponse.results && seqResponse.results[0]) {
308
+ const result = seqResponse.results[0];
275
309
  if (result.type === "error") {
276
310
  throw new DatabaseError(result.error?.message || 'Sequence execution failed', result.error?.code);
277
311
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/serverless",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",