@workglow/storage 0.0.58 → 0.0.59

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/node.js CHANGED
@@ -1519,13 +1519,31 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1519
1519
  return this.db;
1520
1520
  }
1521
1521
  jsToSqlValue(column, value) {
1522
+ if (value !== null && value !== undefined && typeof value === "object") {
1523
+ if (value instanceof Date) {
1524
+ return super.jsToSqlValue(column, value);
1525
+ }
1526
+ if (value instanceof Uint8Array) {
1527
+ return super.jsToSqlValue(column, value);
1528
+ }
1529
+ if (typeof Buffer !== "undefined" && value instanceof Buffer) {
1530
+ return super.jsToSqlValue(column, value);
1531
+ }
1532
+ return JSON.stringify(value);
1533
+ }
1534
+ if (value === null) {
1535
+ const typeDef2 = this.schema.properties[column];
1536
+ if (typeDef2 && this.isNullable(typeDef2)) {
1537
+ return null;
1538
+ }
1539
+ }
1522
1540
  const typeDef = this.schema.properties[column];
1523
1541
  if (typeDef) {
1524
1542
  const actualType = this.getNonNullType(typeDef);
1525
- if (typeof actualType !== "boolean" && actualType.type === "boolean") {
1526
- if (value === null && this.isNullable(typeDef)) {
1527
- return null;
1528
- }
1543
+ const isObject = typeDef === true || typeof actualType !== "boolean" && actualType.type === "object";
1544
+ const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
1545
+ const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
1546
+ if (isBoolean) {
1529
1547
  const v = value;
1530
1548
  if (typeof v === "boolean")
1531
1549
  return v ? 1 : 0;
@@ -1534,8 +1552,22 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1534
1552
  if (typeof v === "string")
1535
1553
  return v === "1" || v.toLowerCase() === "true" ? 1 : 0;
1536
1554
  }
1555
+ if ((isObject || isArray) && value !== null && typeof value === "object") {
1556
+ if (!(value instanceof Date) && !(value instanceof Uint8Array) && (typeof Buffer === "undefined" || !(value instanceof Buffer))) {
1557
+ if (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype) {
1558
+ return JSON.stringify(value);
1559
+ }
1560
+ }
1561
+ }
1562
+ }
1563
+ const result = super.jsToSqlValue(column, value);
1564
+ if (result !== null && typeof result === "object") {
1565
+ const resultObj = result;
1566
+ if (!(resultObj instanceof Uint8Array) && (typeof Buffer === "undefined" || !(resultObj instanceof Buffer))) {
1567
+ return JSON.stringify(resultObj);
1568
+ }
1537
1569
  }
1538
- return super.jsToSqlValue(column, value);
1570
+ return result;
1539
1571
  }
1540
1572
  sqlToJsValue(column, value) {
1541
1573
  const typeDef = this.schema.properties[column];
@@ -1544,14 +1576,27 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1544
1576
  return null;
1545
1577
  }
1546
1578
  const actualType = this.getNonNullType(typeDef);
1547
- if (typeof actualType !== "boolean" && actualType.type === "boolean") {
1579
+ const isObject = typeDef === true || typeof actualType !== "boolean" && actualType.type === "object";
1580
+ const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
1581
+ const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
1582
+ if (isBoolean) {
1548
1583
  const v = value;
1549
1584
  if (typeof v === "boolean")
1550
1585
  return v;
1551
1586
  if (typeof v === "number")
1552
- return v !== 0;
1587
+ return v !== 0 ? true : false;
1553
1588
  if (typeof v === "string")
1554
- return v === "1" || v.toLowerCase() === "true";
1589
+ return v === "1" || v.toLowerCase() === "true" ? true : false;
1590
+ }
1591
+ if (isArray || isObject) {
1592
+ if (typeof value === "string") {
1593
+ try {
1594
+ return JSON.parse(value);
1595
+ } catch (e) {
1596
+ return value;
1597
+ }
1598
+ }
1599
+ return value;
1555
1600
  }
1556
1601
  }
1557
1602
  return super.sqlToJsValue(column, value);
@@ -1603,6 +1648,50 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1603
1648
  const primaryKeyParams = this.getPrimaryKeyAsOrderedArray(key);
1604
1649
  const valueParams = this.getValueAsOrderedArray(value);
1605
1650
  const params = [...primaryKeyParams, ...valueParams];
1651
+ for (let i = 0;i < params.length; i++) {
1652
+ let param = params[i];
1653
+ if (param === undefined) {
1654
+ params[i] = null;
1655
+ continue;
1656
+ }
1657
+ if (param !== null && typeof param === "object") {
1658
+ const paramObj = param;
1659
+ if (paramObj instanceof Uint8Array) {
1660
+ continue;
1661
+ }
1662
+ if (typeof Buffer !== "undefined" && paramObj instanceof Buffer) {
1663
+ params[i] = new Uint8Array(paramObj);
1664
+ continue;
1665
+ }
1666
+ try {
1667
+ params[i] = JSON.stringify(paramObj);
1668
+ } catch (e) {
1669
+ throw new Error(`Failed to stringify param at index ${i} for column binding: ${String(e)}`);
1670
+ }
1671
+ continue;
1672
+ }
1673
+ }
1674
+ const invalidParams = [];
1675
+ for (let i = 0;i < params.length; i++) {
1676
+ const param = params[i];
1677
+ if (param === null || param === undefined || typeof param === "string" || typeof param === "number" || typeof param === "boolean" || typeof param === "bigint") {
1678
+ continue;
1679
+ }
1680
+ if (typeof param === "object") {
1681
+ const paramObj = param;
1682
+ if (paramObj instanceof Uint8Array || typeof Buffer !== "undefined" && paramObj instanceof Buffer) {
1683
+ continue;
1684
+ }
1685
+ invalidParams.push({ index: i, type: typeof param, value: param });
1686
+ } else {
1687
+ invalidParams.push({ index: i, type: typeof param, value: param });
1688
+ }
1689
+ }
1690
+ if (invalidParams.length > 0) {
1691
+ console.error("Invalid params detected:", invalidParams);
1692
+ console.error("All params:", params.map((p, i) => ({ i, type: typeof p, value: p, isArray: Array.isArray(p) })));
1693
+ throw new Error(`Invalid SQLite params detected at indices: ${invalidParams.map((p) => p.index).join(", ")}`);
1694
+ }
1606
1695
  const updatedEntity = stmt.get(...params);
1607
1696
  for (const k in this.schema.properties) {
1608
1697
  updatedEntity[k] = this.sqlToJsValue(k, updatedEntity[k]);
@@ -1630,6 +1719,17 @@ class SqliteTabularRepository extends BaseSqlTabularRepository {
1630
1719
  const primaryKeyParams = this.getPrimaryKeyAsOrderedArray(key);
1631
1720
  const valueParams = this.getValueAsOrderedArray(value);
1632
1721
  const params = [...primaryKeyParams, ...valueParams];
1722
+ for (let i = 0;i < params.length; i++) {
1723
+ let param = params[i];
1724
+ if (param === undefined) {
1725
+ params[i] = null;
1726
+ } else if (param !== null && typeof param === "object") {
1727
+ const paramObj = param;
1728
+ if (!(paramObj instanceof Uint8Array) && (typeof Buffer === "undefined" || !(paramObj instanceof Buffer))) {
1729
+ params[i] = JSON.stringify(paramObj);
1730
+ }
1731
+ }
1732
+ }
1633
1733
  const updatedEntity = stmt.get(...params);
1634
1734
  for (const k in this.schema.properties) {
1635
1735
  updatedEntity[k] = this.sqlToJsValue(k, updatedEntity[k]);
@@ -5641,4 +5741,4 @@ export {
5641
5741
  CACHED_TABULAR_REPOSITORY
5642
5742
  };
5643
5743
 
5644
- //# debugId=A8A981E6F7A25E7F64756E2164756E21
5744
+ //# debugId=252A6E832532D65264756E2164756E21