@inflector/optima 1.1.3 → 1.1.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.
@@ -95,6 +95,7 @@ var zodToDuckDBType = (zodType) => {
95
95
  if (zodType instanceof z.ZodBoolean) return "BOOLEAN";
96
96
  if (zodType instanceof z.ZodDate) return "TIMESTAMP";
97
97
  if (zodType instanceof z.ZodBigInt) return "BIGINT";
98
+ if (zodType instanceof z.ZodAny) return "VARCHAR";
98
99
  if ("element" in (def ?? {})) {
99
100
  const innerType = zodToDuckDBType(def.element);
100
101
  return `${innerType}[]`;
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  Timestamp,
20
20
  Uuid,
21
21
  refHelpers
22
- } from "./chunk-JTCM2KCM.js";
22
+ } from "./chunk-NDIBGCDT.js";
23
23
 
24
24
  // src/database.ts
25
25
  import { DuckDBInstance } from "@duckdb/node-api";
@@ -295,7 +295,9 @@ var notRegexp = (value) => cond().notRegexp(value);
295
295
  var escape = (val) => {
296
296
  if (val === null || val === void 0) return "NULL";
297
297
  if (typeof val === "bigint") return val.toString();
298
- if (typeof val === "string") return `'${val.replace(/'/g, "''")}'`;
298
+ if (typeof val === "string") {
299
+ return `'${val.replace(/\\/g, "\\\\").replace(/'/g, "''")}'`;
300
+ }
299
301
  if (val instanceof Date) return `'${val.toISOString()}'`;
300
302
  if (typeof val === "boolean") return val ? "TRUE" : "FALSE";
301
303
  if (typeof val === "object") {
@@ -303,7 +305,7 @@ var escape = (val) => {
303
305
  val,
304
306
  (_, v) => typeof v === "bigint" ? v.toString() : v
305
307
  );
306
- return `'${safe.replace(/'/g, "''")}'`;
308
+ return `'${safe.replace(/\\/g, "\\\\").replace(/'/g, "''")}'`;
307
309
  }
308
310
  return String(val);
309
311
  };
@@ -464,7 +466,7 @@ ${valuesBlock}${isReturning ? "\nRETURNING *" : ""};`;
464
466
  return Number(value);
465
467
  }
466
468
  if (Array.isArray(value)) {
467
- return value.map((item) => this.parseRecursive(item));
469
+ return value.map((item) => this.parseRecursive(item, type));
468
470
  }
469
471
  if (typeof value === "object") {
470
472
  if ("micros" in value && typeof value.micros === "bigint") {
@@ -472,20 +474,23 @@ ${valuesBlock}${isReturning ? "\nRETURNING *" : ""};`;
472
474
  return new Date(millis);
473
475
  }
474
476
  if (value.entries !== void 0) {
475
- return this.parseRecursive(value.entries);
477
+ return this.parseRecursive(value.entries, type);
476
478
  }
477
479
  if (value.items !== void 0) {
478
- return this.parseRecursive(value.items);
480
+ return this.parseRecursive(value.items, type);
479
481
  }
480
482
  const parsedObj = {};
481
483
  for (const [k, v] of Object.entries(value)) {
482
- parsedObj[k] = this.parseRecursive(v);
484
+ parsedObj[k] = this.parseRecursive(v, type);
483
485
  }
484
486
  return parsedObj;
485
487
  }
486
488
  if (type?.SQlType === "STRUCT" && type?.STRUCTType === "STRUCT()") {
487
489
  return JSON.parse(value);
488
490
  }
491
+ if (type?.SQlType === "LIST" && type?.STRUCTType === "VARCHAR[]") {
492
+ return JSON.parse(value);
493
+ }
489
494
  return value;
490
495
  };
491
496
  this.FormatOut = (data) => {
@@ -624,15 +629,19 @@ ${valuesBlock}${isReturning ? "\nRETURNING *" : ""};`;
624
629
  if (PotentialyUpdated.length == 0) return [];
625
630
  else {
626
631
  const { sql } = this.BuildUpdate(this.Name, record, data);
627
- const Result = await (await this.Connection.run(sql)).getRowObjects();
632
+ const Result = this.FormatOut(await (await this.Connection.run(sql)).getRowObjects());
628
633
  if (Result.length != 0) {
634
+ const paired = PotentialyUpdated.map((oldItem, i) => ({
635
+ old: oldItem,
636
+ new: Result[i]
637
+ }));
629
638
  this.notifyChange({
630
639
  event: "Update",
631
- data: data.returning ? this.FormatOut(Result) : void 0,
640
+ data: data.returning ? paired : void 0,
632
641
  time: /* @__PURE__ */ new Date()
633
642
  });
634
643
  }
635
- return data.returning ? this.FormatOut(Result) : this.SafeParse(Result);
644
+ return data.returning ? Result : this.SafeParse(Result);
636
645
  }
637
646
  });
638
647
  }
package/dist/types.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  Timestamp,
20
20
  Uuid,
21
21
  refHelpers
22
- } from "./chunk-JTCM2KCM.js";
22
+ } from "./chunk-NDIBGCDT.js";
23
23
  export {
24
24
  Array,
25
25
  BigInt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/optima",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "author": "Inflector",
6
6
  "main": "./dist/index.js",